Skip to contentSkip to conversation

q35 chipset support for native pci express support

PATCH In review Isaku Yamahata 11 participants 71 messages Mar 16, 2011 – May 26, 2011 Kbuild

lore
Share & tools
lore
#0 lore raw

cover q35 chipset support for native pci express support

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Example:
qemu-system-x86_64 ... -M pc_q35 -acpitable 'load_header,data=roms/seabios/src/q35-acpi-dsdt.aml

The motivation is to support newer hardware features because piix chipset is very old.
Especially I have PCI express in mind and this is the basic infrastructure for PCI express hot plug and PCI express native direct attach. I can boot Linux with PCIe MMCONFIG with APIC mode pci interrupt routing. I haven't tested other OSes.

The patch series consist as following

- Firstly, some PCI patches which introduce helper functions and so on.
- Then, PC initialization related patches which simplifies pc board initialization, pc_init1().
- Thirdly, factoring out the logics which are common to the existing piix and q35. ie. smram, pam and acpi logic.
- At last introduce q35 chipset emulator which is able to handle pci express natively.

Thanks,

Change from v7:
- heavily reorganized and improved.
- factoring out code duplication.
- improved irq routing fully.

Changes from split out piix specific part from pc emulator. V6
- rebased to 731c54f86988d3f28268f184fabfe9b2a32fb5d3
- PCIe MMCONFIG
- pci bridge related fixes
- chipset emulator works.
- IOAPIC patches

Changes from v5:
- rebased 0.11.0-rc0
- changed qemu_system_powerdown_register() to call qemu_system_shutdown_request() if qemu_system_shutdown() is called before registering.

Changes from v4:
- fix version number.
- rebased anthony's staging tree whose latest change set is 62969268f876c547ee64da6d60e0f363e0f1df75

Changes from v3:
- move qemu_system_powerdown() in vl.c and more generic following the comment by Marcelo Tosatti <[email protected]> acpi.c: make qemu_system_powerdown() piix independent.
- define cmos_set_s3_resume_init() and cmos_set_s3_resume() in pc.c even if TARGET_I386 isn't defined following th ecommit by Paolo Bonzini <[email protected]>
pc.c: remove a global variable, RTCState *rtc_state.
- minor compilation fixes

Changes from v2:
- clean up pc_pci_device_init() not to use unnecessary braces.

Changes from v1:
- make patches full bisectable
- typo s/allocte/allocate/
- some minor fixes
- dropped a merged patch

Isaku Yamahata (26):
pci: replace the magic, 256, for the maximum of slot
pci: add opaque argument to pci_map_irq_fn
pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt
pin swizzle
pci: add accessor function to get irq levels
piix_pci: eliminate PIIX3State::pci_irq_levels
pci_bridge: add helper function to convert PCIBridge into PCIDevice pci/p2pbr: generic pci p2p bridge
apb_pci: simplify apb_pci.c by using pci_p2pbr
dec_pci: simplify dec_pci.c by using pci_p2pbr ide/ahci/ich: use qdev.reset
ahci: add ide device initialization helper
usb/uhci: generalize initialization
usb/uhci: add ich9 usb uhci id's device
ide: consolidate drive_get(IF_IDE)
smbus_eeprom: consolidate smbus eeprom creation
pc, pc_piix: split out allocating isa irqs
pc, pc_piix: split out pc nic initialization
ioapic: move ioapic_init() from pc_piix.c to pc.c pc/piix_pci: factor out smram/pam logic
pc, i440fx: simply i440fx initialization
acpi, acpi_piix: factor out PM_TMR logic
acpi, acpi_piix: factor out PM1a EVT logic
acpi, acpi_piix: factor out PM1_CNT logic
acpi, acpi_piix: factor out GPE logic
pci_ids: add intel 82801BA pci-to-pci bridge id and
PCI_CLASS_SERIAL_SMBUS
pc q35 based chipset emulator

 Makefile.objs      |    2 +-
 Makefile.target    |    3 +-
 hw/acpi.c          |  197 ++++++++++++
 hw/acpi.h          |   68 ++++
 hw/acpi_ich9.c     |  314 +++++++++++++++++++
 hw/acpi_ich9.h     |   53 ++++
 hw/acpi_piix4.c    |  220 ++++----------
 hw/apb_pci.c       |   67 ++---
 hw/bonito.c        |    2 +-
 hw/dec_pci.c       |   51 +---
 hw/grackle_pci.c   |    2 +-
 hw/gt64xxx.c       |    2 +-
 hw/ide.h           |    6 +
 hw/ide/ahci.c      |   15 +
 hw/ide/core.c      |   14 +
 hw/ide/ich.c       |    9 +-
 hw/mips_fulong2e.c |   18 +-
 hw/mips_malta.c    |   22 +--
 hw/mips_r4k.c      |   10 +-
 hw/pam.c           |  128 ++++++++
 hw/pam.h           |   96 ++++++
 hw/pc.c            |   47 +++-
 hw/pc.h            |    7 +-
 hw/pc_piix.c       |   64 +----
 hw/pc_q35.c        |  359 +++++++++++++++++++++
 hw/pci.c           |   27 ++-
 hw/pci.h           |    6 +-
 hw/pci_bridge.c    |    6 +
 hw/pci_bridge.h    |    1 +
 hw/pci_ids.h       |   17 +
 hw/pci_internals.h |    2 +-
 hw/pci_p2pbr.c     |  151 +++++++++
 hw/pci_p2pbr.h     |   61 ++++
 hw/piix_pci.c      |  117 +++-----
 hw/ppc4xx_pci.c    |    2 +-
 hw/ppc_newworld.c  |   11 +-
 hw/ppc_oldworld.c  |   11 +-
 hw/ppc_prep.c      |   10 +-
 hw/ppce500_pci.c   |    2 +-
 hw/prep_pci.c      |    2 +-
 hw/q35.c           |  877 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/q35.h           |  271 ++++++++++++++++
 hw/q35_smbus.c     |  154 +++++++++
 hw/sh_pci.c        |    2 +-
 hw/smbus.h         |    3 +
 hw/smbus_eeprom.c  |   22 ++-
 hw/sun4u.c         |    9 +-
 hw/unin_pci.c      |    2 +-
 hw/usb-uhci.c      |   93 +++---
 hw/versatile_pci.c |    2 +-
 50 files changed, 3116 insertions(+), 521 deletions(-)
 create mode 100644 hw/acpi_ich9.c
 create mode 100644 hw/acpi_ich9.h
 create mode 100644 hw/pam.c
 create mode 100644 hw/pam.h
 create mode 100644 hw/pc_q35.c
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
 create mode 100644 hw/q35.c
 create mode 100644 hw/q35.h
 create mode 100644 hw/q35_smbus.c
#1 lore raw

PATCH 1/26 pci: replace the magic, 256, for the maximum of slot

Introduce symbol PCI_SLOT_MAX for the maximum of slot. and replace the magic, 256.

Cc Michael S. Tsirkin <[email protected]>
---
 hw/pci.h           |    1 +
 hw/pci_internals.h |    2 +-
 2 files changed, 2 insertions(+), 1 deletions(-)
hw/pci.h +1 -0
index 113e556..7d56337 100644
@@ -16,6 +16,7 @@
 #define PCI_DEVFN(slot, func)   ((((slot) & 0x1f) << 3) | ((func) & 0x07))
 #define PCI_SLOT(devfn)         (((devfn) >> 3) & 0x1f)
 #define PCI_FUNC(devfn)         ((devfn) & 0x07)
+#define PCI_SLOT_MAX            32
 #define PCI_FUNC_MAX            8
 
 /* Class, Vendor and Device IDs from Linux's pci_ids.h */
hw/pci_internals.h +1 -1
index e3c93a3..efaefcd 100644
@@ -22,7 +22,7 @@ struct PCIBus {
     pci_hotplug_fn hotplug;
     DeviceState *hotplug_qdev;
     void *irq_opaque;
-    PCIDevice *devices[256];
+    PCIDevice *devices[PCI_SLOT_MAX * PCI_FUNC_MAX];
     PCIDevice *parent_dev;
     target_phys_addr_t mem_base;
 
Signature · 1 line
1.7.1.1
#2 lore raw

PATCH 2/26 pci: add opaque argument to pci_map_irq_fn

In reply to Isaku Yamahata

Pass opaque argument to pci_map_irq_fn like pci_set_irq_fn. ICH9 irq routing is not static, but configurable by chipset configuration registers, so the corresponding irq mapping function of pci_map_irq_fn needs to know the pointer to ich9.

Cc Michael S. Tsirkin <[email protected]>
---
 hw/apb_pci.c       |    4 ++--
 hw/bonito.c        |    2 +-
 hw/dec_pci.c       |    2 +-
 hw/grackle_pci.c   |    2 +-
 hw/gt64xxx.c       |    2 +-
 hw/pci.c           |    2 +-
 hw/pci.h           |    2 +-
 hw/piix_pci.c      |    2 +-
 hw/ppc4xx_pci.c    |    2 +-
 hw/ppce500_pci.c   |    2 +-
 hw/prep_pci.c      |    2 +-
 hw/sh_pci.c        |    2 +-
 hw/unin_pci.c      |    2 +-
 hw/versatile_pci.c |    2 +-
 14 files changed, 15 insertions(+), 15 deletions(-)
hw/apb_pci.c +2 -2
index 84e9af7..c56ea9a 100644
@@ -264,12 +264,12 @@ static CPUReadMemoryFunc * const pci_apb_ioread[] = {
 };
 
 /* The APB host has an IRQ line for each IRQ line of each slot.  */
-static int pci_apb_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_apb_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return ((pci_dev->devfn & 0x18) >> 1) + irq_num;
 }
 
-static int pci_pbm_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_pbm_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int bus_offset;
     if (pci_dev->devfn & 1)
hw/bonito.c +1 -1
index 65a4a63..94e69f5 100644
@@ -632,7 +632,7 @@ static void pci_bonito_set_irq(void *opaque, int irq_num, int level)
 }
 
 /* map the original irq (0~3) to bonito irq (16~47, but 16~31 are unused) */
-static int pci_bonito_map_irq(PCIDevice * pci_dev, int irq_num)
+static int pci_bonito_map_irq(void *opaque, PCIDevice * pci_dev, int irq_num)
 {
     int slot;
 
hw/dec_pci.c +1 -1
index bf88f2a..3cc4f04 100644
@@ -45,7 +45,7 @@ typedef struct DECState {
     PCIHostState host_state;
 } DECState;
 
-static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
+static int dec_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return irq_num;
 }
hw/grackle_pci.c +1 -1
index d35701f..4ed1ec6 100644
@@ -44,7 +44,7 @@ typedef struct GrackleState {
 } GrackleState;
 
 /* Don't know if this matches real hardware, but it agrees with OHW.  */
-static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_grackle_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return (irq_num + (pci_dev->devfn >> 3)) & 3;
 }
hw/gt64xxx.c +1 -1
index c66188f..e6e2828 100644
@@ -862,7 +862,7 @@ static CPUReadMemoryFunc * const gt64120_read[] = {
     &gt64120_readl,
 };
 
-static int gt64120_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int gt64120_pci_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int slot;
 
hw/pci.c +1 -1
index 8d7bfff..5349488 100644
@@ -117,7 +117,7 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
     PCIBus *bus;
     for (;;) {
         bus = pci_dev->bus;
-        irq_num = bus->map_irq(pci_dev, irq_num);
+        irq_num = bus->map_irq(bus->irq_opaque, pci_dev, irq_num);
         if (bus->set_irq)
             break;
         pci_dev = bus->parent_dev;
hw/pci.h +1 -1
index 7d56337..1a08139 100644
@@ -219,7 +219,7 @@ void pci_device_save(PCIDevice *s, QEMUFile *f);
 int pci_device_load(PCIDevice *s, QEMUFile *f);
 
 typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
-typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
+typedef int (*pci_map_irq_fn)(void *opaque, PCIDevice *pci_dev, int irq_num);
 
 typedef enum {
     PCI_HOTPLUG_DISABLED,
hw/piix_pci.c +1 -1
index 358da58..892c576 100644
@@ -60,7 +60,7 @@ static void piix3_set_irq(void *opaque, int irq_num, int level);
 /* return the global irq number corresponding to a given device irq
    pin. We could also use the bus number to have a more precise
    mapping. */
-static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
+static int pci_slot_get_pirq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int slot_addend;
     slot_addend = (pci_dev->devfn >> 3) - 1;
hw/ppc4xx_pci.c +1 -1
index f62f1f9..11ca763 100644
@@ -267,7 +267,7 @@ static void ppc4xx_pci_reset(void *opaque)
 
 /* On Bamboo, all pins from each slot are tied to a single board IRQ. This
  * may need further refactoring for other boards. */
-static int ppc4xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int ppc4xx_pci_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int slot = pci_dev->devfn >> 3;
 
hw/ppce500_pci.c +1 -1
index 11edd03..029a3f9 100644
@@ -187,7 +187,7 @@ static CPUWriteMemoryFunc * const e500_pci_reg_write[] = {
     &pci_reg_write4,
 };
 
-static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int mpc85xx_pci_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int devno = pci_dev->devfn >> 3, ret = 0;
 
hw/prep_pci.c +1 -1
index f88b825..8287246 100644
@@ -98,7 +98,7 @@ static CPUReadMemoryFunc * const PPC_PCIIO_read[] = {
     &PPC_PCIIO_readl,
 };
 
-static int prep_map_irq(PCIDevice *pci_dev, int irq_num)
+static int prep_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return (irq_num + (pci_dev->devfn >> 3)) & 1;
 }
hw/sh_pci.c +1 -1
index e99d8db..f108759 100644
@@ -93,7 +93,7 @@ static MemOp sh_pci_reg = {
     { NULL, NULL, sh_pci_reg_write },
 };
 
-static int sh_pci_map_irq(PCIDevice *d, int irq_num)
+static int sh_pci_map_irq(void *opaque, PCIDevice *d, int irq_num)
 {
     return (d->devfn >> 3);
 }
hw/unin_pci.c +1 -1
index c57c0a1..1496625 100644
@@ -44,7 +44,7 @@ typedef struct UNINState {
     ReadWriteHandler data_handler;
 } UNINState;
 
-static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_unin_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int retval;
     int devfn = pci_dev->devfn & 0x00FFFFFF;
hw/versatile_pci.c +1 -1
index 2fed8a0..c002fb2 100644
@@ -74,7 +74,7 @@ static CPUReadMemoryFunc * const pci_vpb_config_read[] = {
     &pci_vpb_config_readl,
 };
 
-static int pci_vpb_map_irq(PCIDevice *d, int irq_num)
+static int pci_vpb_map_irq(void *opaque, PCIDevice *d, int irq_num)
 {
     return irq_num;
 }
Signature · 1 line
1.7.1.1
#3 lore raw

[Qemu-devel] Re: [PATCH 02/26] pci: add opaque argument to pci_map_irq_fn

Quoted 7 lines · Isaku Yamahata

Pass opaque argument to pci_map_irq_fn like pci_set_irq_fn. ICH9 irq routing is not static, but configurable by chipset configuration registers, so the corresponding irq mapping function of pci_map_irq_fn needs to know the pointer to ich9.

Cc Michael S. Tsirkin <[email protected]>

Not an objection to this patch - just thinking aloud: as mapping changes rarely, something I wanted to do for a while now is replace the walk up the bus with indirect function calls
at each step on each set_irq call with:
- walk down the bus on each mapping change, update all devices
- pci_set_irq which is not indirect, just calls directly to the interrupt controller

But we can do this optimization later.

Quoted 207 lines
---
 hw/apb_pci.c       |    4 ++--
 hw/bonito.c        |    2 +-
 hw/dec_pci.c       |    2 +-
 hw/grackle_pci.c   |    2 +-
 hw/gt64xxx.c       |    2 +-
 hw/pci.c           |    2 +-
 hw/pci.h           |    2 +-
 hw/piix_pci.c      |    2 +-
 hw/ppc4xx_pci.c    |    2 +-
 hw/ppce500_pci.c   |    2 +-
 hw/prep_pci.c      |    2 +-
 hw/sh_pci.c        |    2 +-
 hw/unin_pci.c      |    2 +-
 hw/versatile_pci.c |    2 +-
 14 files changed, 15 insertions(+), 15 deletions(-)
hw/apb_pci.c +2 -2
index 84e9af7..c56ea9a 100644
@@ -264,12 +264,12 @@ static CPUReadMemoryFunc * const pci_apb_ioread[] = {
 };
 
 /* The APB host has an IRQ line for each IRQ line of each slot.  */
-static int pci_apb_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_apb_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return ((pci_dev->devfn & 0x18) >> 1) + irq_num;
 }
 
-static int pci_pbm_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_pbm_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int bus_offset;
     if (pci_dev->devfn & 1)
hw/bonito.c +1 -1
index 65a4a63..94e69f5 100644
@@ -632,7 +632,7 @@ static void pci_bonito_set_irq(void *opaque, int irq_num, int level)
 }
 
 /* map the original irq (0~3) to bonito irq (16~47, but 16~31 are unused) */
-static int pci_bonito_map_irq(PCIDevice * pci_dev, int irq_num)
+static int pci_bonito_map_irq(void *opaque, PCIDevice * pci_dev, int irq_num)
 {
     int slot;
 
hw/dec_pci.c +1 -1
index bf88f2a..3cc4f04 100644
@@ -45,7 +45,7 @@ typedef struct DECState {
     PCIHostState host_state;
 } DECState;
 
-static int dec_map_irq(PCIDevice *pci_dev, int irq_num)
+static int dec_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return irq_num;
 }
hw/grackle_pci.c +1 -1
index d35701f..4ed1ec6 100644
@@ -44,7 +44,7 @@ typedef struct GrackleState {
 } GrackleState;
 
 /* Don't know if this matches real hardware, but it agrees with OHW.  */
-static int pci_grackle_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_grackle_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return (irq_num + (pci_dev->devfn >> 3)) & 3;
 }
hw/gt64xxx.c +1 -1
index c66188f..e6e2828 100644
@@ -862,7 +862,7 @@ static CPUReadMemoryFunc * const gt64120_read[] = {
     &gt64120_readl,
 };
 
-static int gt64120_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int gt64120_pci_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int slot;
 
hw/pci.c +1 -1
index 8d7bfff..5349488 100644
@@ -117,7 +117,7 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
     PCIBus *bus;
     for (;;) {
         bus = pci_dev->bus;
-        irq_num = bus->map_irq(pci_dev, irq_num);
+        irq_num = bus->map_irq(bus->irq_opaque, pci_dev, irq_num);
         if (bus->set_irq)
             break;
         pci_dev = bus->parent_dev;
hw/pci.h +1 -1
index 7d56337..1a08139 100644
@@ -219,7 +219,7 @@ void pci_device_save(PCIDevice *s, QEMUFile *f);
 int pci_device_load(PCIDevice *s, QEMUFile *f);
 
 typedef void (*pci_set_irq_fn)(void *opaque, int irq_num, int level);
-typedef int (*pci_map_irq_fn)(PCIDevice *pci_dev, int irq_num);
+typedef int (*pci_map_irq_fn)(void *opaque, PCIDevice *pci_dev, int irq_num);
 
 typedef enum {
     PCI_HOTPLUG_DISABLED,
hw/piix_pci.c +1 -1
index 358da58..892c576 100644
@@ -60,7 +60,7 @@ static void piix3_set_irq(void *opaque, int irq_num, int level);
 /* return the global irq number corresponding to a given device irq
    pin. We could also use the bus number to have a more precise
    mapping. */
-static int pci_slot_get_pirq(PCIDevice *pci_dev, int irq_num)
+static int pci_slot_get_pirq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int slot_addend;
     slot_addend = (pci_dev->devfn >> 3) - 1;
hw/ppc4xx_pci.c +1 -1
index f62f1f9..11ca763 100644
@@ -267,7 +267,7 @@ static void ppc4xx_pci_reset(void *opaque)
 
 /* On Bamboo, all pins from each slot are tied to a single board IRQ. This
  * may need further refactoring for other boards. */
-static int ppc4xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int ppc4xx_pci_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int slot = pci_dev->devfn >> 3;
 
hw/ppce500_pci.c +1 -1
index 11edd03..029a3f9 100644
@@ -187,7 +187,7 @@ static CPUWriteMemoryFunc * const e500_pci_reg_write[] = {
     &pci_reg_write4,
 };
 
-static int mpc85xx_pci_map_irq(PCIDevice *pci_dev, int irq_num)
+static int mpc85xx_pci_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int devno = pci_dev->devfn >> 3, ret = 0;
 
hw/prep_pci.c +1 -1
index f88b825..8287246 100644
@@ -98,7 +98,7 @@ static CPUReadMemoryFunc * const PPC_PCIIO_read[] = {
     &PPC_PCIIO_readl,
 };
 
-static int prep_map_irq(PCIDevice *pci_dev, int irq_num)
+static int prep_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     return (irq_num + (pci_dev->devfn >> 3)) & 1;
 }
hw/sh_pci.c +1 -1
index e99d8db..f108759 100644
@@ -93,7 +93,7 @@ static MemOp sh_pci_reg = {
     { NULL, NULL, sh_pci_reg_write },
 };
 
-static int sh_pci_map_irq(PCIDevice *d, int irq_num)
+static int sh_pci_map_irq(void *opaque, PCIDevice *d, int irq_num)
 {
     return (d->devfn >> 3);
 }
hw/unin_pci.c +1 -1
index c57c0a1..1496625 100644
@@ -44,7 +44,7 @@ typedef struct UNINState {
     ReadWriteHandler data_handler;
 } UNINState;
 
-static int pci_unin_map_irq(PCIDevice *pci_dev, int irq_num)
+static int pci_unin_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
 {
     int retval;
     int devfn = pci_dev->devfn & 0x00FFFFFF;
hw/versatile_pci.c +1 -1
index 2fed8a0..c002fb2 100644
@@ -74,7 +74,7 @@ static CPUReadMemoryFunc * const pci_vpb_config_read[] = {
     &pci_vpb_config_readl,
 };
 
-static int pci_vpb_map_irq(PCIDevice *d, int irq_num)
+static int pci_vpb_map_irq(void *opaque, PCIDevice *d, int irq_num)
 {
     return irq_num;
 }
Signature · 1 line
1.7.1.1
#4 lore raw

PATCH 3/26 pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt pin swizzle

In reply to Isaku Yamahata

introduce pci_swizzle_map_irq_fn() for interrupt pin swizzle which is standardized. PCI bridge swizzle is common logic, by introducing this function duplicated swizzle logic will be avoided later.

Cc Michael S. Tsirkin <[email protected]>
---
 hw/pci.c |   18 ++++++++++++++++++
 hw/pci.h |    2 ++
 2 files changed, 20 insertions(+), 0 deletions(-)
hw/pci.c +18 -0
index 5349488..d6c5e66 100644
@@ -1117,6 +1117,24 @@ static void pci_set_irq(void *opaque, int irq_num, int level)
     pci_change_irq_level(pci_dev, irq_num, change);
 }
 
+/*
+ * PCI-to-PCI bridge specification
+ * 9.1: Interrupt routing. Table 9-1
+ *
+ * the PCI Express Base Specification, Revision 2.1
+ * 2.2.8.1: INTx interrutp signaling - Rules
+ *          the Implementation Note
+ *          Table 2-20
+ */
+/*
+ * 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD
+ * 0-origin unlike PCI interrupt pin register.
+ */
+int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin)
+{
+    return (pin + PCI_SLOT(pci_dev->devfn)) % PCI_NUM_PINS;
+}
+
 /***********************************************************/
 /* monitor info on PCI */
 
hw/pci.h +2 -0
index 1a08139..46b3ad3 100644
@@ -235,6 +235,8 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
 void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                   void *irq_opaque, int nirq);
 void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);
+/* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
+int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin);
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
                          pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          void *irq_opaque, int devfn_min, int nirq);
Signature · 1 line
1.7.1.1
#5 lore raw

[Qemu-devel] Re: [PATCH 03/26] pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt pin swizzle

Quoted 6 lines · Isaku Yamahata

introduce pci_swizzle_map_irq_fn() for interrupt pin swizzle which is standardized. PCI bridge swizzle is common logic, by introducing this function duplicated swizzle logic will be avoided later.

Cc Michael S. Tsirkin <[email protected]>

As long as it's used on data path, better to inline it?

Quoted 49 lines
---
 hw/pci.c |   18 ++++++++++++++++++
 hw/pci.h |    2 ++
 2 files changed, 20 insertions(+), 0 deletions(-)
hw/pci.c +18 -0
index 5349488..d6c5e66 100644
@@ -1117,6 +1117,24 @@ static void pci_set_irq(void *opaque, int irq_num, int level)
     pci_change_irq_level(pci_dev, irq_num, change);
 }
 
+/*
+ * PCI-to-PCI bridge specification
+ * 9.1: Interrupt routing. Table 9-1
+ *
+ * the PCI Express Base Specification, Revision 2.1
+ * 2.2.8.1: INTx interrutp signaling - Rules
+ *          the Implementation Note
+ *          Table 2-20
+ */
+/*
+ * 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD
+ * 0-origin unlike PCI interrupt pin register.
+ */
+int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin)
+{
+    return (pin + PCI_SLOT(pci_dev->devfn)) % PCI_NUM_PINS;
+}
+
 /***********************************************************/
 /* monitor info on PCI */
 
hw/pci.h +2 -0
index 1a08139..46b3ad3 100644
@@ -235,6 +235,8 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
 void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                   void *irq_opaque, int nirq);
 void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);
+/* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
+int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin);
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
                          pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          void *irq_opaque, int devfn_min, int nirq);
Signature · 1 line
1.7.1.1
#6 lore raw

Re: [Qemu-devel] Re: [PATCH 03/26] pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt pin swizzle

Quoted 9 lines · Michael S. Tsirkin
Quoted 6 lines · Isaku Yamahata

introduce pci_swizzle_map_irq_fn() for interrupt pin swizzle which is standardized. PCI bridge swizzle is common logic, by introducing this function duplicated swizzle logic will be avoided later.

Cc Michael S. Tsirkin <[email protected]>

As long as it's used on data path, better to inline it?

The function is passed for pci_map_irq_fn as function pointer. So inlining doesn't make sense.

Quoted 51 lines
Quoted 50 lines
---
 hw/pci.c |   18 ++++++++++++++++++
 hw/pci.h |    2 ++
 2 files changed, 20 insertions(+), 0 deletions(-)
hw/pci.c +18 -0
index 5349488..d6c5e66 100644
@@ -1117,6 +1117,24 @@ static void pci_set_irq(void *opaque, int irq_num, int level)
     pci_change_irq_level(pci_dev, irq_num, change);
 }
 
+/*
+ * PCI-to-PCI bridge specification
+ * 9.1: Interrupt routing. Table 9-1
+ *
+ * the PCI Express Base Specification, Revision 2.1
+ * 2.2.8.1: INTx interrutp signaling - Rules
+ *          the Implementation Note
+ *          Table 2-20
+ */
+/*
+ * 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD
+ * 0-origin unlike PCI interrupt pin register.
+ */
+int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin)
+{
+    return (pin + PCI_SLOT(pci_dev->devfn)) % PCI_NUM_PINS;
+}
+
 /***********************************************************/
 /* monitor info on PCI */
 
hw/pci.h +2 -0
index 1a08139..46b3ad3 100644
@@ -235,6 +235,8 @@ PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
 void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                   void *irq_opaque, int nirq);
 void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);
+/* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
+int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin);
 PCIBus *pci_register_bus(DeviceState *parent, const char *name,
                          pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                          void *irq_opaque, int devfn_min, int nirq);
Signature · 1 line
1.7.1.1
Signature · 1 line
yamahata
#7 lore raw

PATCH 4/26 pci: add accessor function to get irq levels

In reply to Isaku Yamahata

Introduce accessor function to know INTx levels.
It will be used later by q35.
Although piix_pci tracks the intx line levels, it can be eliminated by this helper function.

Cc Michael S. Tsirkin <[email protected]>
---
 hw/pci.c |    7 +++++++
 hw/pci.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)
hw/pci.c +7 -0
index d6c5e66..67cb3d7 100644
@@ -126,6 +126,13 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
     bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0);
 }
 
+int pci_bus_get_irq_level(PCIBus *bus, int irq_num)
+{
+    assert(irq_num >= 0);
+    assert(irq_num < bus->nirq);
+    return !!bus->irq_count[irq_num];
+}
+
 /* Update interrupt status bit in config space on interrupt
  * state change. */
 static void pci_update_irq_status(PCIDevice *dev)
hw/pci.h +1 -0
index 46b3ad3..f523722 100644
@@ -234,6 +234,7 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
 PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
 void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                   void *irq_opaque, int nirq);
+int pci_bus_get_irq_level(PCIBus *bus, int irq_num);
 void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);
 /* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
 int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin);
Signature · 1 line
1.7.1.1
#8 lore raw

[Qemu-devel] Re: [PATCH 04/26] pci: add accessor function to get irq levels

Quoted 4 lines · Isaku Yamahata

Introduce accessor function to know INTx levels.
It will be used later by q35.
Although piix_pci tracks the intx line levels, it can be eliminated by this helper function.

At least for piix, the right thing to IMO is to have bit per IRQ, then the for loop can be replaced with a single !!. There's a TODO there which this will fix. I think we can reuse pci device irq_state for this: need to check. Haven't looked at q35 yet - applies there as well?

Quoted 40 lines
Cc Michael S. Tsirkin <[email protected]>
---
 hw/pci.c |    7 +++++++
 hw/pci.h |    1 +
 2 files changed, 8 insertions(+), 0 deletions(-)
hw/pci.c +7 -0
index d6c5e66..67cb3d7 100644
@@ -126,6 +126,13 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change)
     bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0);
 }
 
+int pci_bus_get_irq_level(PCIBus *bus, int irq_num)
+{
+    assert(irq_num >= 0);
+    assert(irq_num < bus->nirq);
+    return !!bus->irq_count[irq_num];
+}
+
 /* Update interrupt status bit in config space on interrupt
  * state change. */
 static void pci_update_irq_status(PCIDevice *dev)
hw/pci.h +1 -0
index 46b3ad3..f523722 100644
@@ -234,6 +234,7 @@ void pci_bus_new_inplace(PCIBus *bus, DeviceState *parent,
 PCIBus *pci_bus_new(DeviceState *parent, const char *name, int devfn_min);
 void pci_bus_irqs(PCIBus *bus, pci_set_irq_fn set_irq, pci_map_irq_fn map_irq,
                   void *irq_opaque, int nirq);
+int pci_bus_get_irq_level(PCIBus *bus, int irq_num);
 void pci_bus_hotplug(PCIBus *bus, pci_hotplug_fn hotplug, DeviceState *dev);
 /* 0 <= pin <= 3 0 = INTA, 1 = INTB, 2 = INTC, 3 = INTD */
 int pci_swizzle_map_irq_fn(void *opaque, PCIDevice *pci_dev, int pin);
Signature · 1 line
1.7.1.1
#9 lore raw

[Qemu-devel] Re: [PATCH 04/26] pci: add accessor function to get irq levels

Quoted 11 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata

Introduce accessor function to know INTx levels.
It will be used later by q35.
Although piix_pci tracks the intx line levels, it can be eliminated by this helper function.

At least for piix, the right thing to IMO is to have bit per IRQ, then the for loop can be replaced with a single !!. There's a TODO there which this will fix. I think we can reuse pci device irq_state for this: need to check. Haven't looked at q35 yet - applies there as well?

Yes, such bitmap optimization is possible.
But this accessor function is still necessary,
please see the following. (I didn't do any test yet. Just to show the idea) If you like it, I'll post it as separate patch.

hw/piix_pci.c +40 -12
index 151353c..82b7daf 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 typedef struct PIIX3State {
     PCIDevice dev;
+    unsigned long irq_level[16];
     int32_t dummy_for_save_load_compat[4];
     qemu_irq *pic;
 } PIIX3State;
@@ -200,25 +201,51 @@ PCIBus *i440fx_init(int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size)
 }
 
 /* PIIX3 PCI to ISA bridge */
-
 static void piix3_set_irq(void *opaque, int irq_num, int level)
 {
     int i, pic_irq, pic_level;
     PIIX3State *piix3 = opaque;
 
-    /* now we change the pic irq level according to the piix irq mappings */
-    /* XXX: optimize */
     pic_irq = piix3->dev.config[0x60 + irq_num];
-    if (pic_irq < 16) {
-        /* The pic level is the logical OR of all the PCI irqs mapped
-           to it */
-        pic_level = 0;
-        for (i = 0; i < 4; i++) {
-            if (pic_irq == piix3->dev.config[0x60 + i]) {
-                pic_level |= pci_bus_get_irq_level(piix3->dev.bus, i);
-            }
+    if (pic_irq >= 16) {
+        return;
+    }
+
+    /* The pic level is the logical OR of all the PCI irqs mapped to it */
+    if (level) {
+        set_bit(&piix3->irq_level[pic_irq], irq_num);
+    } else {
+        clear_bit(&piix3->irq_level[pic_irq], irq_num);
+    }
+    qemu_set_irq(piix3->pic[pic_irq], !!piix3->irq_level[pic_irq]);
+}
+
+/* irq routing is changed. so rebuild bitmap */
+static void piix3_update_irq_levels(PIIX3State *piix3)
+{
+    int i;
+    for (i = 0; i < 16; i++) {
+        piix3->irq_level[i] = 0;
+    }
+    for (i = 0; i < 4; i++) {
+        int pic_irq = piix3->dev.config[0x60 + irq_num];
+        if (pic_irq >= 16) {
+            continue;
+        }
+        if (pci_bus_get_irq_level(piix3->dev.bus, i)) {
+            set_bit(&piix3->irq_level[pic_irq], i);
         }
-        qemu_set_irq(piix3->pic[pic_irq], pic_level);
+    }
+}
+
+static void piix3_write_config(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len)
+{
+    PIIX3State *piix3 = DO_UPCAST(PIIX3State, dev, dev);
+
+    pci_default_write_config(dev, address, val, len);
+    if (ranges_overlap(address, len, 0x60, 4)) {
+        piix3_update_irq_levels(piix3);
     }
 }
 
@@ -318,6 +345,7 @@ static PCIDeviceInfo i440fx_info[] = {
         .qdev.no_user = 1,
         .no_hotplug   = 1,
         .init         = piix3_initfn,
+        .config_write = piix3_write_config,
     },{
         /* end of list */
     }
Signature · 1 line
yamahata
#10 lore raw

[Qemu-devel] Re: [PATCH 04/26] pci: add accessor function to get irq levels

Quoted 7 lines · Isaku Yamahata
Quoted 6 lines · Michael S. Tsirkin
Quoted 4 lines · Isaku Yamahata

Introduce accessor function to know INTx levels.
It will be used later by q35.
Although piix_pci tracks the intx line levels, it can be eliminated by this helper function.

Quoted 8 lines
Quoted 5 lines

At least for piix, the right thing to IMO is to have bit per IRQ, then the for loop can be replaced with a single !!. There's a TODO there which this will fix. I think we can reuse pci device irq_state for this: need to check. Haven't looked at q35 yet - applies there as well?

Yes, such bitmap optimization is possible.
But this accessor function is still necessary,

OK, I'm convinced. It makes sense off data path, much easier than try to unswizzle and swizzle back to the new values.

Quoted 2 lines

please see the following. (I didn't do any test yet. Just to show the idea) If you like it, I'll post it as separate patch.

Yes. BTW as long as we touch it, we might want some symbolic name for constants 0x60, 16, and use PCI_NUM_PINS instead of 4. Some more suggestions below.

Also, save/restore needs to be updated.

hw/piix_pci.c typedef PCIHostState I440FXState; · line 43

Quoted 9 lines
hw/piix_pci.c +1 -0
index 151353c..82b7daf 100644
@@ -40,6 +40,7 @@ typedef PCIHostState I440FXState;
 
 typedef struct PIIX3State {
     PCIDevice dev;
+    unsigned long irq_level[16];

That's 1024 bits. We really only need 4*16 = 64 bits. Also pic_levels might be a better name.
So just
uint64_t pic_levels;

Maybe stick a check there:
#if PCI_NUM_PINS * PIIX_NUM_PIC_IRQS > 64
#error unable to encode pic state in 64 bit in pic_levels #endif
Also, need to clear on init?

Quoted 24 lines
hw/piix_pci.c +0 -11
     int32_t dummy_for_save_load_compat[4];
     qemu_irq *pic;
 } PIIX3State;
@@ -200,25 +201,51 @@ PCIBus *i440fx_init(int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size)
 }
 
 /* PIIX3 PCI to ISA bridge */
-
 static void piix3_set_irq(void *opaque, int irq_num, int level)
 {
     int i, pic_irq, pic_level;
     PIIX3State *piix3 = opaque;
 
-    /* now we change the pic irq level according to the piix irq mappings */
-    /* XXX: optimize */
     pic_irq = piix3->dev.config[0x60 + irq_num];
-    if (pic_irq < 16) {
-        /* The pic level is the logical OR of all the PCI irqs mapped
-           to it */
-        pic_level = 0;
-        for (i = 0; i < 4; i++) {
-            if (pic_irq == piix3->dev.config[0x60 + i]) {
-                pic_level |= pci_bus_get_irq_level(piix3->dev.bus, i);
-            }

hw/piix_pci.c PCIBus *i440fx_init(int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size) · line 219

Quoted 10 lines
hw/piix_pci.c +10 -0
+    if (pic_irq >= 16) {
+        return;
+    }
+
+    /* The pic level is the logical OR of all the PCI irqs mapped to it */
+    if (level) {
+        set_bit(&piix3->irq_level[pic_irq], irq_num);
+    } else {
+        clear_bit(&piix3->irq_level[pic_irq], irq_num);
+    }

We can do this without a branch too I think (assuming uint64_t suggested above):

	mask = 0x1ull << (pic_irq * 16 + irq_num);
	piix3->pic_levels &= ~mask;
	piix3->pic_levels |= mask;

hw/piix_pci.c PCIBus *i440fx_init(int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size) · line 229

Quoted 10 lines
hw/piix_pci.c +10 -0
+    qemu_set_irq(piix3->pic[pic_irq], !!piix3->irq_level[pic_irq]);
+}
+
+/* irq routing is changed. so rebuild bitmap */
+static void piix3_update_irq_levels(PIIX3State *piix3)
+{
+    int i;
+    for (i = 0; i < 16; i++) {
+        piix3->irq_level[i] = 0;
+    }

memset(piix3->irq_level, 0, sizeof piix3->irq_level);

hw/piix_pci.c PCIBus *i440fx_init(int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size) · line 221

Quoted 9 lines
hw/piix_pci.c +7 -1
+    for (i = 0; i < 4; i++) {
+        int pic_irq = piix3->dev.config[0x60 + irq_num];
+        if (pic_irq >= 16) {
+            continue;
+        }
+        if (pci_bus_get_irq_level(piix3->dev.bus, i)) {
+            set_bit(&piix3->irq_level[pic_irq], i);
         }
-        qemu_set_irq(piix3->pic[pic_irq], pic_level);

Hmm, don't we need to set the levels in guest appropriately?

There's also some duplication here.
Can't we just do

	for (i = 0; i < 4; i++) {
		piix3_set_irq(piix3, i, pci_bus_get_irq_level(piix3->dev.bus, i));
	}

?

Quoted 25 lines
hw/piix_pci.c +12 -0
+    }
+}
+
+static void piix3_write_config(PCIDevice *dev,
+                               uint32_t address, uint32_t val, int len)
+{
+    PIIX3State *piix3 = DO_UPCAST(PIIX3State, dev, dev);
+
+    pci_default_write_config(dev, address, val, len);
+    if (ranges_overlap(address, len, 0x60, 4)) {
+        piix3_update_irq_levels(piix3);
     }
 }
 
@@ -318,6 +345,7 @@ static PCIDeviceInfo i440fx_info[] = {
         .qdev.no_user = 1,
         .no_hotplug   = 1,
         .init         = piix3_initfn,
+        .config_write = piix3_write_config,
     },{
         /* end of list */
     }
Signature · 2 lines
-- 
yamahata
#11 lore raw

PATCH 5/26 piix_pci: eliminate PIIX3State::pci_irq_levels

In reply to Isaku Yamahata

PIIX3State::pci_irq_levels are redundant which is already tracked by PCIBus layer. So eliminate them.

---
 hw/piix_pci.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)
hw/piix_pci.c +21 -10
index 892c576..2d0ad9b 100644
@@ -39,7 +39,7 @@ typedef PCIHostState I440FXState;
 
 typedef struct PIIX3State {
     PCIDevice dev;
-    int pci_irq_levels[4];
+    int32_t dummy_for_save_load_compat[4];
     qemu_irq *pic;
 } PIIX3State;
 
@@ -162,9 +162,11 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)
     i440fx_update_memory_mappings(d);
     qemu_get_8s(f, &d->smm_enabled);
 
-    if (version_id == 2)
-        for (i = 0; i < 4; i++)
-            d->piix3->pci_irq_levels[i] = qemu_get_be32(f);
+    if (version_id == 2) {
+        for (i = 0; i < 4; i++) {
+            qemu_get_be32(f); /* dummy load for compatibility */
+        }
+    }
 
     return 0;
 }
@@ -256,8 +258,6 @@ static void piix3_set_irq(void *opaque, int irq_num, int level)
     int i, pic_irq, pic_level;
     PIIX3State *piix3 = opaque;
 
-    piix3->pci_irq_levels[irq_num] = level;
-
     /* now we change the pic irq level according to the piix irq mappings */
     /* XXX: optimize */
     pic_irq = piix3->dev.config[0x60 + irq_num];
@@ -266,8 +266,9 @@ static void piix3_set_irq(void *opaque, int irq_num, int level)
            to it */
         pic_level = 0;
         for (i = 0; i < 4; i++) {
-            if (pic_irq == piix3->dev.config[0x60 + i])
-                pic_level |= piix3->pci_irq_levels[i];
+            if (pic_irq == piix3->dev.config[0x60 + i]) {
+                pic_level |= pci_bus_get_irq_level(piix3->dev.bus, i);
+            }
         }
         qemu_set_irq(piix3->pic[pic_irq], pic_level);
     }
@@ -309,8 +310,17 @@ static void piix3_reset(void *opaque)
     pci_conf[0xab] = 0x00;
     pci_conf[0xac] = 0x00;
     pci_conf[0xae] = 0x00;
+}
 
-    memset(d->pci_irq_levels, 0, sizeof(d->pci_irq_levels));
+static void piix3_pre_save(void *opaque)
+{
+    int i;
+    PIIX3State *piix3 = opaque;
+
+    for (i = 0; i < ARRAY_SIZE(piix3->dummy_for_save_load_compat); i++) {
+        piix3->dummy_for_save_load_compat[i] =
+            pci_bus_get_irq_level(piix3->dev.bus, i);
+    }
 }
 
 static const VMStateDescription vmstate_piix3 = {
@@ -318,9 +328,10 @@ static const VMStateDescription vmstate_piix3 = {
     .version_id = 3,
     .minimum_version_id = 2,
     .minimum_version_id_old = 2,
+    .pre_save = piix3_pre_save,
     .fields      = (VMStateField []) {
         VMSTATE_PCI_DEVICE(dev, PIIX3State),
-        VMSTATE_INT32_ARRAY_V(pci_irq_levels, PIIX3State, 4, 3),
+        VMSTATE_INT32_ARRAY_V(dummy_for_save_load_compat, PIIX3State, 4, 3),
         VMSTATE_END_OF_LIST()
     }
 };
Signature · 1 line
1.7.1.1
#12 lore raw

PATCH 6/26 pci_bridge: add helper function to convert PCIBridge into PCIDevice

In reply to Isaku Yamahata

pci_bridge_to_pci() which converts PCIBridge into PCIDevice which will be used later by pci_p2pbr.

Cc Michael S. Tsirkin <[email protected]>
---
 hw/pci_bridge.c |    6 ++++++
 hw/pci_bridge.h |    1 +
 2 files changed, 7 insertions(+), 0 deletions(-)
hw/pci_bridge.c +6 -0
index 464d897..00b6b76 100644
@@ -52,6 +52,12 @@ int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
     return pos;
 }
 
+/* Accessor function to get PCI device from pci bridge. */
+PCIDevice *pci_bridge_to_pci(PCIBridge *br)
+{
+    return &br->dev;
+}
+
 /* Accessor function to get parent bridge device from pci bus. */
 PCIDevice *pci_bridge_get_device(PCIBus *bus)
 {
hw/pci_bridge.h +1 -0
index 84411a6..c306992 100644
@@ -31,6 +31,7 @@
 int pci_bridge_ssvid_init(PCIDevice *dev, uint8_t offset,
                           uint16_t svid, uint16_t ssid);
 
+PCIDevice *pci_bridge_to_pci(PCIBridge *br);
 PCIDevice *pci_bridge_get_device(PCIBus *bus);
 PCIBus *pci_bridge_get_sec_bus(PCIBridge *br);
 
Signature · 1 line
1.7.1.1
#13 lore raw

PATCH 7/26 pci/p2pbr: generic pci p2p bridge

In reply to Isaku Yamahata

Create generic pci p2p bridge device which can be customized via properties like vendor id/device id and so on. With this, we can avoid to create many pci p2p bridge which only differs in those ids.

Cc Michael S. Tsirkin <[email protected]>
---
 Makefile.objs  |    2 +-
 hw/pci_p2pbr.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pci_p2pbr.h |   61 +++++++++++++++++++++++
 3 files changed, 213 insertions(+), 1 deletions(-)
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
Makefile.objs +1 -1
index a52f42f..5cb7010 100644
@@ -171,7 +171,7 @@ hw-obj-y =
 hw-obj-y += vl.o loader.o
 hw-obj-$(CONFIG_VIRTIO) += virtio.o virtio-console.o
 hw-obj-y += fw_cfg.o
-hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o
+hw-obj-$(CONFIG_PCI) += pci.o pci_bridge.o pci_p2pbr.o
 hw-obj-$(CONFIG_PCI) += msix.o msi.o
 hw-obj-$(CONFIG_PCI) += pci_host.o pcie_host.o
 hw-obj-$(CONFIG_PCI) += ioh3420.o xio3130_upstream.o xio3130_downstream.o
hw/pci_p2pbr.c new file +151 -0

151 lines not on this page · raw message

hw/pci_p2pbr.h new file +61 -0

61 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#14 lore raw

[Qemu-devel] Re: [PATCH 07/26] pci/p2pbr: generic pci p2p bridge

Quoted 7 lines · Isaku Yamahata

Create generic pci p2p bridge device which can be customized via properties like vendor id/device id and so on. With this, we can avoid to create many pci p2p bridge which only differs in those ids.

Cc Michael S. Tsirkin <[email protected]>

So we added 213 lines and we saved all of 20 in other places? Maybe I miss the point ...

Quoted 7 lines
---
 Makefile.objs  |    2 +-
 hw/pci_p2pbr.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pci_p2pbr.h |   61 +++++++++++++++++++++++
 3 files changed, 213 insertions(+), 1 deletions(-)
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
#15 lore raw

Re: [Qemu-devel] Re: [PATCH 07/26] pci/p2pbr: generic pci p2p bridge

Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata

Create generic pci p2p bridge device which can be customized via properties like vendor id/device id and so on. With this, we can avoid to create many pci p2p bridge which only differs in those ids.

Cc Michael S. Tsirkin <[email protected]>

So we added 213 lines and we saved all of 20 in other places? Maybe I miss the point ...

What are missing is,
- The patch eliminates logic duplication rather than simple
line insertion/deletion.
- It also simplifies q35 code which is 26/26. Its code saving isn't counted.
- The lines of newly added copyright notice are counted.
- If line saving is so important, the numbers of lines can be reduced dramatically by accepting 14 arguments functions instead of using struct. struct initialization bloated line insertion. But I think it doesn't increase code complexity.

Anyway this patch isn't very critical. I think the available choice is

- this patch
- modify the patch to use 14 arguments function.
Thus we can save much more lines.
- Add one more p2p bridge code which q35 uses, accepting same code which differs only in IDs.
- any other ideas?

Which option do you prefer?

Quoted 10 lines
Quoted 9 lines

---
 Makefile.objs  |    2 +-
 hw/pci_p2pbr.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pci_p2pbr.h |   61 +++++++++++++++++++++++
 3 files changed, 213 insertions(+), 1 deletions(-)
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
Signature · 1 line
yamahata
#16 lore raw

Re: [Qemu-devel] Re: [PATCH 07/26] pci/p2pbr: generic pci p2p bridge

Quoted 13 lines · Isaku Yamahata
Quoted 11 lines · Michael S. Tsirkin
Quoted 7 lines · Isaku Yamahata

Create generic pci p2p bridge device which can be customized via properties like vendor id/device id and so on. With this, we can avoid to create many pci p2p bridge which only differs in those ids.

Cc Michael S. Tsirkin <[email protected]>

So we added 213 lines and we saved all of 20 in other places? Maybe I miss the point ...

Quoted 10 lines

What are missing is,
- The patch eliminates logic duplication rather than simple
line insertion/deletion.
- It also simplifies q35 code which is 26/26. Its code saving isn't counted.
- The lines of newly added copyright notice are counted.
- If line saving is so important, the numbers of lines can be reduced dramatically by accepting 14 arguments functions instead of using struct. struct initialization bloated line insertion. But I think it doesn't increase code complexity.

But doesn't seem to reduce it either.
Line count is just an attempt to see how well the abstraction works. All this one does is move from pci_config_set_vendor_id(dev, XXX) to .vendor_id = XXX. This just does not seem to be a big win.

qdev properties are also user-visible, aren't they? Adding properties that, if changed, will confuse the guest doesn't seem to be a good idea either.

Quoted 10 lines

Anyway this patch isn't very critical. I think the available choice is

- this patch
- modify the patch to use 14 arguments function.
Thus we can save much more lines.
- Add one more p2p bridge code which q35 uses, accepting same code which differs only in IDs.
- any other ideas?

Which option do you prefer?

Add one more bridge for q35.

Quoted 13 lines
Quoted 10 lines
Quoted 9 lines

---
 Makefile.objs  |    2 +-
 hw/pci_p2pbr.c |  151 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pci_p2pbr.h |   61 +++++++++++++++++++++++
 3 files changed, 213 insertions(+), 1 deletions(-)
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
Signature · 1 line
yamahata
#17 lore raw

Re: [Qemu-devel] Re: [PATCH 07/26] pci/p2pbr: generic pci p2p bridge

Quoted 9 lines · Michael S. Tsirkin
Quoted 9 lines

Anyway this patch isn't very critical. I think the available choice is

- this patch
- modify the patch to use 14 arguments function.
Thus we can save much more lines.
- Add one more p2p bridge code which q35 uses, accepting same code which differs only in IDs.
- any other ideas?

Quoted 3 lines
Quoted 1 line

Which option do you prefer?

Add one more bridge for q35.

Okay.
How about other pci related patches? I think they are trivial.

Signature · 1 line
yamahata
#18 lore raw

Re: [Qemu-devel] Re: [PATCH 07/26] pci/p2pbr: generic pci p2p bridge

Quoted 10 lines · Isaku Yamahata
Quoted 9 lines · Michael S. Tsirkin
Quoted 9 lines

Anyway this patch isn't very critical. I think the available choice is

- this patch
- modify the patch to use 14 arguments function.
Thus we can save much more lines.
- Add one more p2p bridge code which q35 uses, accepting same code which differs only in IDs.
- any other ideas?

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Which option do you prefer?

Add one more bridge for q35.

Okay.
How about other pci related patches? I think they are trivial.

I'll look at the usage to see how good new APIs are.

Quoted 2 lines
Signature · 1 line
yamahata
#19 lore raw

PATCH 8/26 apb_pci: simplify apb_pci.c by using pci_p2pbr

In reply to Isaku Yamahata

apply pci_p2pbr for apb_pci.c.

Cc Michael S. Tsirkin <[email protected]>
Cc Blue Swirl <[email protected]>
---
 hw/apb_pci.c |   63 ++++++++++++++++++++++++---------------------------------
 1 files changed, 27 insertions(+), 36 deletions(-)
hw/apb_pci.c +27 -36
index c56ea9a..c9f2a6b 100644
@@ -31,6 +31,7 @@
 #include "pci_host.h"
 #include "pci_bridge.h"
 #include "pci_internals.h"
+#include "pci_p2pbr.h"
 #include "rwhandler.h"
 #include "apb_pci.h"
 #include "sysemu.h"
@@ -297,16 +298,6 @@ static void pci_apb_set_irq(void *opaque, int irq_num, int level)
 
 static int apb_pci_bridge_initfn(PCIDevice *dev)
 {
-    int rc;
-
-    rc = pci_bridge_initfn(dev);
-    if (rc < 0) {
-        return rc;
-    }
-
-    pci_config_set_vendor_id(dev->config, PCI_VENDOR_ID_SUN);
-    pci_config_set_device_id(dev->config, PCI_DEVICE_ID_SUN_SIMBA);
-
     /*
      * command register:
      * According to PCI bridge spec, after reset
@@ -321,10 +312,31 @@ static int apb_pci_bridge_initfn(PCIDevice *dev)
     pci_set_word(dev->config + PCI_STATUS,
                  PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ |
                  PCI_STATUS_DEVSEL_MEDIUM);
-    pci_set_byte(dev->config + PCI_REVISION_ID, 0x11);
     return 0;
 }
 
+static PCIBridge *apb_pci_bridge_init(PCIBus *bus,
+                                      uint8_t devfn, const char *bus_name)
+{
+    const PCIP2PBridgeInit init = {
+        .bus = bus,
+        .devfn = devfn,
+        .multifunction = true,
+
+        .bus_name = bus_name,
+        .map_irq = pci_apb_map_irq,
+
+        .initfn = apb_pci_bridge_initfn,
+    };
+    const PCIP2PBridgeProp prop = {
+        .vendor_id = PCI_VENDOR_ID_SUN,
+        .device_id = PCI_DEVICE_ID_SUN_SIMBA,
+        .revision_id = 0x11,
+    };
+
+    return pci_p2pbr_create_simple(&init, &prop);
+}
+
 PCIBus *pci_apb_init(target_phys_addr_t special_base,
                      target_phys_addr_t mem_base,
                      qemu_irq *pic, PCIBus **bus2, PCIBus **bus3)
@@ -333,7 +345,6 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,
     SysBusDevice *s;
     APBState *d;
     unsigned int i;
-    PCIDevice *pci_dev;
     PCIBridge *br;
 
     /* Ultrasparc PBM main bus */
@@ -360,20 +371,12 @@ PCIBus *pci_apb_init(target_phys_addr_t special_base,
     pci_create_simple(d->bus, 0, "pbm");
 
     /* APB secondary busses */
-    pci_dev = pci_create_multifunction(d->bus, PCI_DEVFN(1, 0), true,
-                                   "pbm-bridge");
-    br = DO_UPCAST(PCIBridge, dev, pci_dev);
-    pci_bridge_map_irq(br, "Advanced PCI Bus secondary bridge 1",
-                       pci_apb_map_irq);
-    qdev_init_nofail(&pci_dev->qdev);
+    br = apb_pci_bridge_init(d->bus, PCI_DEVFN(1, 0),
+                             "Advanced PCI Bus secondary bridge 1");
     *bus2 = pci_bridge_get_sec_bus(br);
 
-    pci_dev = pci_create_multifunction(d->bus, PCI_DEVFN(1, 1), true,
-                                   "pbm-bridge");
-    br = DO_UPCAST(PCIBridge, dev, pci_dev);
-    pci_bridge_map_irq(br, "Advanced PCI Bus secondary bridge 2",
-                       pci_apb_map_irq);
-    qdev_init_nofail(&pci_dev->qdev);
+    br = apb_pci_bridge_init(d->bus, PCI_DEVFN(1, 1),
+                             "Advanced PCI Bus secondary bridge 2");
     *bus3 = pci_bridge_get_sec_bus(br);
 
     return d->bus;
@@ -461,22 +464,10 @@ static SysBusDeviceInfo pbm_host_info = {
     .init = pci_pbm_init_device,
 };
 
-static PCIDeviceInfo pbm_pci_bridge_info = {
-    .qdev.name = "pbm-bridge",
-    .qdev.size = sizeof(PCIBridge),
-    .qdev.vmsd = &vmstate_pci_device,
-    .qdev.reset = pci_bridge_reset,
-    .init = apb_pci_bridge_initfn,
-    .exit = pci_bridge_exitfn,
-    .config_write = pci_bridge_write_config,
-    .is_bridge = 1,
-};
-
 static void pbm_register_devices(void)
 {
     sysbus_register_withprop(&pbm_host_info);
     pci_qdev_register(&pbm_pci_host_info);
-    pci_qdev_register(&pbm_pci_bridge_info);
 }
 
 device_init(pbm_register_devices)
Signature · 1 line
1.7.1.1
#20 lore raw

[Qemu-devel] Re: [PATCH 08/26] apb_pci: simplify apb_pci.c by using pci_p2pbr

Quoted 54 lines · Isaku Yamahata

apply pci_p2pbr for apb_pci.c.

Cc Michael S. Tsirkin <[email protected]>
Cc Blue Swirl <[email protected]>

---
 hw/apb_pci.c |   63 ++++++++++++++++++++++++---------------------------------

 1 files changed, 27 insertions(+), 36 deletions(-)
hw/apb_pci.c +1 -10
index c56ea9a..c9f2a6b 100644
@@ -31,6 +31,7 @@
  #include "pci_host.h"
  #include "pci_bridge.h"
  #include "pci_internals.h"
+#include "pci_p2pbr.h"
  #include "rwhandler.h"
  #include "apb_pci.h"
  #include "sysemu.h"
@@ -297,16 +298,6 @@ static void pci_apb_set_irq(void *opaque, int irq_num, int level)
 
  static int apb_pci_bridge_initfn(PCIDevice *dev)
  {
-    int rc;
-
-    rc = pci_bridge_initfn(dev);
-    if (rc < 0) {
-        return rc;
-    }
-
-    pci_config_set_vendor_id(dev->config, PCI_VENDOR_ID_SUN);
-    pci_config_set_device_id(dev->config, PCI_DEVICE_ID_SUN_SIMBA);
-
     /*
      * command register:
      * According to PCI bridge spec, after reset
@@ -321,10 +312,31 @@ static int apb_pci_bridge_initfn(PCIDevice *dev)
     pci_set_word(dev->config + PCI_STATUS,

                 PCI_STATUS_FAST_BACK | PCI_STATUS_66MHZ | PCI_STATUS_DEVSEL_MEDIUM);
-    pci_set_byte(dev->config + PCI_REVISION_ID, 0x11); return 0;
 }

hw/apb_pci.c +8 -0
+static PCIBridge *apb_pci_bridge_init(PCIBus *bus,
+                                      uint8_t devfn, const char *bus_name)
+{
+    const PCIP2PBridgeInit init = {
+        .bus = bus,
+        .devfn = devfn,
+        .multifunction = true,
+

hw/apb_pci.c static int apb_pci_bridge_initfn(PCIDevice *dev) · line 335

Quoted 10 lines
hw/apb_pci.c +10 -0
+        .bus_name = bus_name,
+        .map_irq = pci_apb_map_irq,
+
+        .initfn = apb_pci_bridge_initfn,
+    };
+    const PCIP2PBridgeProp prop = {
+        .vendor_id = PCI_VENDOR_ID_SUN,
+        .device_id = PCI_DEVICE_ID_SUN_SIMBA,
+        .revision_id = 0x11,
+    };

'static' again.

#21 lore raw

PATCH 9/26 dec_pci: simplify dec_pci.c by using pci_p2pbr

In reply to Isaku Yamahata

apply pci_p2pbr for dec_pci.c.

Cc Michael S. Tsirkin <[email protected]>
Cc Blue Swirl <[email protected]>
---
 hw/dec_pci.c |   49 ++++++++++++++-----------------------------------
 1 files changed, 14 insertions(+), 35 deletions(-)
hw/dec_pci.c +14 -35
index 3cc4f04..fbd1363 100644
@@ -29,6 +29,7 @@
 #include "pci_host.h"
 #include "pci_bridge.h"
 #include "pci_internals.h"
+#include "pci_p2pbr.h"
 
 /* debug DEC */
 //#define DEBUG_DEC
@@ -50,42 +51,21 @@ static int dec_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
     return irq_num;
 }
 
-static int dec_21154_initfn(PCIDevice *dev)
-{
-    int rc;
-
-    rc = pci_bridge_initfn(dev);
-    if (rc < 0) {
-        return rc;
-    }
-
-    pci_config_set_vendor_id(dev->config, PCI_VENDOR_ID_DEC);
-    pci_config_set_device_id(dev->config, PCI_DEVICE_ID_DEC_21154);
-    return 0;
-}
-
-static PCIDeviceInfo dec_21154_pci_bridge_info = {
-    .qdev.name = "dec-21154-p2p-bridge",
-    .qdev.desc = "DEC 21154 PCI-PCI bridge",
-    .qdev.size = sizeof(PCIBridge),
-    .qdev.vmsd = &vmstate_pci_device,
-    .qdev.reset = pci_bridge_reset,
-    .init = dec_21154_initfn,
-    .exit = pci_bridge_exitfn,
-    .config_write = pci_bridge_write_config,
-    .is_bridge = 1,
-};
-
 PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
 {
-    PCIDevice *dev;
-    PCIBridge *br;
-
-    dev = pci_create_multifunction(parent_bus, devfn, false,
-                                   "dec-21154-p2p-bridge");
-    br = DO_UPCAST(PCIBridge, dev, dev);
-    pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
-    qdev_init_nofail(&dev->qdev);
+    const PCIP2PBridgeInit init = {
+        .bus = parent_bus,
+        .devfn = devfn,
+        .multifunction = false,
+
+        .bus_name = "DEC 21154 PCI-PCI bridge",
+        .map_irq = dec_map_irq,
+    };
+    const PCIP2PBridgeProp prop = {
+        .vendor_id = PCI_VENDOR_ID_DEC,
+        .device_id = PCI_DEVICE_ID_DEC_21154,
+    };
+    PCIBridge *br = pci_p2pbr_create_simple(&init, &prop);
     return pci_bridge_get_sec_bus(br);
 }
 
@@ -127,7 +107,6 @@ static void dec_register_devices(void)
     sysbus_register_dev("dec-21154", sizeof(DECState),
                         pci_dec_21154_init_device);
     pci_qdev_register(&dec_21154_pci_host_info);
-    pci_qdev_register(&dec_21154_pci_bridge_info);
 }
 
 device_init(dec_register_devices)
Signature · 1 line
1.7.1.1
#22 lore raw

[Qemu-devel] Re: [PATCH 09/26] dec_pci: simplify dec_pci.c by using pci_p2pbr

Quoted 63 lines · Isaku Yamahata

apply pci_p2pbr for dec_pci.c.

Cc Michael S. Tsirkin <[email protected]>
Cc Blue Swirl <[email protected]>

---
 hw/dec_pci.c |   49 ++++++++++++++-----------------------------------

 1 files changed, 14 insertions(+), 35 deletions(-)
hw/dec_pci.c +3 -34
index 3cc4f04..fbd1363 100644
@@ -29,6 +29,7 @@
  #include "pci_host.h"
  #include "pci_bridge.h"
  #include "pci_internals.h"
+#include "pci_p2pbr.h"
 
  /* debug DEC */
  //#define DEBUG_DEC
@@ -50,42 +51,21 @@ static int dec_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num)
     return irq_num;
  }
 
-static int dec_21154_initfn(PCIDevice *dev)
-{
-    int rc;
-
-    rc = pci_bridge_initfn(dev);
-    if (rc < 0) {
-        return rc;
-    }
-
-    pci_config_set_vendor_id(dev->config, PCI_VENDOR_ID_DEC);
-    pci_config_set_device_id(dev->config, PCI_DEVICE_ID_DEC_21154);
-    return 0;
-}
-
-static PCIDeviceInfo dec_21154_pci_bridge_info = {
-    .qdev.name = "dec-21154-p2p-bridge",
-    .qdev.desc = "DEC 21154 PCI-PCI bridge",
-    .qdev.size = sizeof(PCIBridge),
-    .qdev.vmsd = &vmstate_pci_device,
-    .qdev.reset = pci_bridge_reset,
-    .init = dec_21154_initfn,
-    .exit = pci_bridge_exitfn,
-    .config_write = pci_bridge_write_config,
-    .is_bridge = 1,
-};
-
  PCIBus *pci_dec_21154_init(PCIBus *parent_bus, int devfn)
  {
-    PCIDevice *dev;
-    PCIBridge *br;
-
-    dev = pci_create_multifunction(parent_bus, devfn, false,
-                                   "dec-21154-p2p-bridge");
-    br = DO_UPCAST(PCIBridge, dev, dev);
-    pci_bridge_map_irq(br, "DEC 21154 PCI-PCI bridge", dec_map_irq);
-    qdev_init_nofail(&dev->qdev);
+    const PCIP2PBridgeInit init = {
+        .bus = parent_bus,

hw/dec_pci.c static int dec_map_irq(void *opaque, PCIDevice *pci_dev, int irq_num) · line 67

Quoted 10 lines
hw/dec_pci.c +10 -0
+        .devfn = devfn,
+        .multifunction = false,
+
+        .bus_name = "DEC 21154 PCI-PCI bridge",
+        .map_irq = dec_map_irq,
+    };
+    const PCIP2PBridgeProp prop = {
+        .vendor_id = PCI_VENDOR_ID_DEC,
+        .device_id = PCI_DEVICE_ID_DEC_21154,
+    };

I'd make the above structures static.

Quoted 16 lines
hw/dec_pci.c +1 -2
+    PCIBridge *br = pci_p2pbr_create_simple(&init, &prop);
     return pci_bridge_get_sec_bus(br);
  }
 
@@ -127,7 +107,6 @@ static void dec_register_devices(void)
     sysbus_register_dev("dec-21154", sizeof(DECState),
                         pci_dec_21154_init_device);
     pci_qdev_register(&dec_21154_pci_host_info);
-    pci_qdev_register(&dec_21154_pci_bridge_info);
  }
 
  device_init(dec_register_devices)
--

1.7.1.1

#23 lore raw

PATCH 10/26 ide/ahci/ich: use qdev.reset

In reply to Isaku Yamahata

use DeviceInfo::reset callback instead of qemu_register_reset(). With this patch, its reset is done before parent pci device's reset.

---
 hw/ide/ich.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)
hw/ide/ich.c +6 -3
index f242d7a..e190f24 100644
@@ -92,8 +92,6 @@ static int pci_ich9_ahci_init(PCIDevice *dev)
     /* XXX Software should program this register */
     d->card.config[0x90]   = 1 << 6; /* Address Map Register - AHCI mode */
 
-    qemu_register_reset(ahci_reset, d);
-
     /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */
     pci_register_bar(&d->card, 5, 0x1000, PCI_BASE_ADDRESS_SPACE_MEMORY,
                      ahci_pci_map);
@@ -115,7 +113,6 @@ static int pci_ich9_uninit(PCIDevice *dev)
         msi_uninit(dev);
     }
 
-    qemu_unregister_reset(ahci_reset, d);
     ahci_uninit(&d->ahci);
 
     return 0;
@@ -128,11 +125,17 @@ static void pci_ich9_write_config(PCIDevice *pci, uint32_t addr,
     msi_write_config(pci, addr, val, len);
 }
 
+static void pci_ich9_resetfn(DeviceState *qdev)
+{
+    ahci_reset(qdev);
+}
+
 static PCIDeviceInfo ich_ahci_info[] = {
     {
         .qdev.name    = "ich9-ahci",
         .qdev.alias   = "ahci",
         .qdev.size    = sizeof(AHCIPCIState),
+        .qdev.reset   = pci_ich9_resetfn,
         .init         = pci_ich9_ahci_init,
         .exit         = pci_ich9_uninit,
         .config_write = pci_ich9_write_config,
Signature · 1 line
1.7.1.1
#24 lore raw

PATCH 11/26 ahci: add ide device initialization helper

In reply to Isaku Yamahata

Introduce a helper function which initialize ahci port with ide device It will be used by q35 support later.

---
 hw/ide.h      |    3 +++
 hw/ide/ahci.c |   15 +++++++++++++++
 2 files changed, 18 insertions(+), 0 deletions(-)
hw/ide.h +3 -0
index 73fb550..e90f557 100644
@@ -28,4 +28,7 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2,
 
 void ide_get_bs(BlockDriverState *bs[], BusState *qbus);
 
+/* ide/ahci.c */
+void pci_ahci_ide_create_devs(PCIDevice *pci_dev, DriveInfo **hd_table);
+
 #endif /* HW_IDE_H */
hw/ide/ahci.c +15 -0
index 98bdf70..5597885 100644
@@ -1150,3 +1150,18 @@ void ahci_reset(void *opaque)
         ahci_reset_port(&d->ahci, i);
     }
 }
+
+void pci_ahci_ide_create_devs(PCIDevice *pci_dev, DriveInfo **hd_table)
+{
+    struct AHCIPCIState *dev = DO_UPCAST(struct AHCIPCIState, card, pci_dev);
+    int i;
+
+    for (i = 0; i < dev->ahci.ports; i++) {
+        /* master device only, ignore slaves */
+        if (hd_table[i * MAX_IDE_DEVS] == NULL) {
+            continue;
+        }
+        ide_create_drive(&dev->ahci.dev[i].port, 0,
+                         hd_table[i * MAX_IDE_DEVS]);
+    }
+}
Signature · 1 line
1.7.1.1
#25 lore raw

PATCH 12/26 usb/uhci: generalize initialization

In reply to Isaku Yamahata

generalize initialization to make vendir/device id customizable.

---
 hw/usb-uhci.c |   87 ++++++++++++++++++++++++++++-----------------------------
 1 files changed, 43 insertions(+), 44 deletions(-)
hw/usb-uhci.c +43 -44
index b384e1d..2fb2a85 100644
@@ -1115,12 +1115,25 @@ static USBPortOps uhci_port_ops = {
     .wakeup = uhci_wakeup,
 };
 
-static int usb_uhci_common_initfn(UHCIState *s)
+typedef struct UHCIDeviceInfo {
+    PCIDeviceInfo pci;
+    uint16_t vendor_id;
+    uint16_t device_id;
+    uint8_t revision_id;
+} UHCIDeviceInfo;
+
+static int usb_uhci_common_initfn(PCIDevice *dev)
 {
+    UHCIDeviceInfo *uhci_info = DO_UPCAST(UHCIDeviceInfo, pci.qdev,
+                                          dev->qdev.info);
+    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
     uint8_t *pci_conf = s->dev.config;
     int i;
 
-    pci_conf[PCI_REVISION_ID] = 0x01; // revision number
+    pci_config_set_vendor_id(pci_conf, uhci_info->vendor_id);
+    pci_config_set_device_id(pci_conf, uhci_info->device_id);
+    pci_config_set_revision(pci_conf, uhci_info->revision_id);
+
     pci_conf[PCI_CLASS_PROG] = 0x00;
     pci_config_set_class(pci_conf, PCI_CLASS_SERIAL_USB);
     /* TODO: reset value should be 0. */
@@ -1148,34 +1161,10 @@ static int usb_uhci_common_initfn(UHCIState *s)
     return 0;
 }
 
-static int usb_uhci_piix3_initfn(PCIDevice *dev)
-{
-    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
-    uint8_t *pci_conf = s->dev.config;
-
-    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
-    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_2);
-    return usb_uhci_common_initfn(s);
-}
-
-static int usb_uhci_piix4_initfn(PCIDevice *dev)
-{
-    UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
-    uint8_t *pci_conf = s->dev.config;
-
-    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
-    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_2);
-    return usb_uhci_common_initfn(s);
-}
-
 static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
 {
     UHCIState *s = DO_UPCAST(UHCIState, dev, dev);
     uint8_t *pci_conf = s->dev.config;
-
-    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_VIA);
-    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_VIA_UHCI);
-
     /* USB misc control 1/2 */
     pci_set_long(pci_conf + 0x40,0x00001000);
     /* PM capability */
@@ -1183,33 +1172,43 @@ static int usb_uhci_vt82c686b_initfn(PCIDevice *dev)
     /* USB legacy support  */
     pci_set_long(pci_conf + 0xc0,0x00002000);
 
-    return usb_uhci_common_initfn(s);
+    return usb_uhci_common_initfn(dev);
 }
 
-static PCIDeviceInfo uhci_info[] = {
+static UHCIDeviceInfo uhci_info[] = {
     {
-        .qdev.name    = "piix3-usb-uhci",
-        .qdev.size    = sizeof(UHCIState),
-        .qdev.vmsd    = &vmstate_uhci,
-        .init         = usb_uhci_piix3_initfn,
-    },{
-        .qdev.name    = "piix4-usb-uhci",
-        .qdev.size    = sizeof(UHCIState),
-        .qdev.vmsd    = &vmstate_uhci,
-        .init         = usb_uhci_piix4_initfn,
+        .pci.qdev.name    = "piix3-usb-uhci",
+        .pci.qdev.size    = sizeof(UHCIState),
+        .pci.qdev.vmsd    = &vmstate_uhci,
+        .pci.init         = usb_uhci_common_initfn,
+        .vendor_id        = PCI_VENDOR_ID_INTEL,
+        .device_id        = PCI_DEVICE_ID_INTEL_82371SB_2,
+        .revision_id      = 0x01,
     },{
-        .qdev.name    = "vt82c686b-usb-uhci",
-        .qdev.size    = sizeof(UHCIState),
-        .qdev.vmsd    = &vmstate_uhci,
-        .init         = usb_uhci_vt82c686b_initfn,
+        .pci.qdev.name    = "piix4-usb-uhci",
+        .pci.qdev.size    = sizeof(UHCIState),
+        .pci.qdev.vmsd    = &vmstate_uhci,
+        .pci.init         = usb_uhci_common_initfn,
+        .vendor_id        = PCI_VENDOR_ID_INTEL,
+        .device_id        = PCI_DEVICE_ID_INTEL_82371AB_2,
+        .revision_id      = 0x01,
     },{
-        /* end of list */
-    }
+        .pci.qdev.name    = "vt82c686b-usb-uhci",
+        .pci.qdev.size    = sizeof(UHCIState),
+        .pci.qdev.vmsd    = &vmstate_uhci,
+        .pci.init         = usb_uhci_vt82c686b_initfn,
+        .vendor_id        = PCI_VENDOR_ID_VIA,
+        .device_id        = PCI_DEVICE_ID_VIA_UHCI,
+        .revision_id      = 0x01,
+    },
 };
 
 static void uhci_register(void)
 {
-    pci_qdev_register_many(uhci_info);
+    int i;
+    for (i = 0; i < ARRAY_SIZE(uhci_info); i++) {
+        pci_qdev_register(&uhci_info[i].pci);
+    }
 }
 device_init(uhci_register);
 
Signature · 1 line
1.7.1.1
#26 lore raw

PATCH 13/26 usb/uhci: add ich9 usb uhci id's device

In reply to Isaku Yamahata

add uhci device which has ich9 device id.

---
 hw/pci_ids.h  |    2 ++
 hw/usb-uhci.c |    8 ++++++++
 2 files changed, 10 insertions(+), 0 deletions(-)
hw/pci_ids.h +2 -0
index ea3418c..9daea23 100644
@@ -108,3 +108,5 @@
 #define PCI_DEVICE_ID_INTEL_82371AB      0x7111
 #define PCI_DEVICE_ID_INTEL_82371AB_2    0x7112
 #define PCI_DEVICE_ID_INTEL_82371AB_3    0x7113
+
+#define PCI_DEVICE_ID_INTEL_ICH9_UCHI1   0x2934
hw/usb-uhci.c +8 -0
index 2fb2a85..247f1bf 100644
@@ -1193,6 +1193,14 @@ static UHCIDeviceInfo uhci_info[] = {
         .device_id        = PCI_DEVICE_ID_INTEL_82371AB_2,
         .revision_id      = 0x01,
     },{
+        .pci.qdev.name    = "ich9-usb-uhci1",
+        .pci.qdev.size    = sizeof(UHCIState),
+        .pci.qdev.vmsd    = &vmstate_uhci,
+        .pci.init         = usb_uhci_common_initfn,
+        .vendor_id        = PCI_VENDOR_ID_INTEL,
+        .device_id        = PCI_DEVICE_ID_INTEL_ICH9_UCHI1,
+        .revision_id      = 0x03,
+    },{
         .pci.qdev.name    = "vt82c686b-usb-uhci",
         .pci.qdev.size    = sizeof(UHCIState),
         .pci.qdev.vmsd    = &vmstate_uhci,
Signature · 1 line
1.7.1.1
#27 lore raw

Re: [Qemu-devel] [PATCH 13/26] usb/uhci: add ich9 usb uhci id's device

Quoted 13 lines · Isaku Yamahata

add uhci device which has ich9 device id.

---
 hw/pci_ids.h  |    2 ++
 hw/usb-uhci.c |    8 ++++++++

 2 files changed, 10 insertions(+), 0 deletions(-)
hw/pci_ids.h +0 -0
index ea3418c..9daea23 100644

hw/pci_ids.h line 112

Quoted 5 lines
hw/pci_ids.h +2 -0
@@ -108,3 +108,5 @@
  #define PCI_DEVICE_ID_INTEL_82371AB      0x7111
  #define PCI_DEVICE_ID_INTEL_82371AB_2    0x7112
  #define PCI_DEVICE_ID_INTEL_82371AB_3    0x7113
+
+#define PCI_DEVICE_ID_INTEL_ICH9_UCHI1   0x2934

s/UCHI/UHCI/g

Quoted 24 lines
hw/usb-uhci.c +8 -1
index 2fb2a85..247f1bf 100644
@@ -1193,6 +1193,14 @@ static UHCIDeviceInfo uhci_info[] = {
         .device_id        = PCI_DEVICE_ID_INTEL_82371AB_2,
         .revision_id      = 0x01,
     },{
+        .pci.qdev.name    = "ich9-usb-uhci1",
+        .pci.qdev.size    = sizeof(UHCIState),
+        .pci.qdev.vmsd    = &vmstate_uhci,
+        .pci.init         = usb_uhci_common_initfn,
+        .vendor_id        = PCI_VENDOR_ID_INTEL,
+        .device_id        = PCI_DEVICE_ID_INTEL_ICH9_UCHI1,
+        .revision_id      = 0x03,
+    },{
         .pci.qdev.name    = "vt82c686b-usb-uhci",
         .pci.qdev.size    = sizeof(UHCIState),
         .pci.qdev.vmsd    = &vmstate_uhci,
--

1.7.1.1

#28 lore raw

PATCH 14/26 ide: consolidate drive_get(IF_IDE)

In reply to Isaku Yamahata

factor out ide initialization to call drive_get(IF_IDE)

---
 hw/ide.h           |    3 +++
 hw/ide/core.c      |   14 ++++++++++++++
 hw/mips_fulong2e.c |    9 +--------
 hw/mips_malta.c    |   10 +---------
 hw/mips_r4k.c      |   10 +---------
 hw/pc_piix.c       |   13 ++-----------
 hw/ppc_newworld.c  |   11 ++---------
 hw/ppc_oldworld.c  |   11 +++--------
 hw/ppc_prep.c      |   10 +---------
 hw/sun4u.c         |    9 +--------
 10 files changed, 29 insertions(+), 71 deletions(-)
hw/ide.h +3 -0
index e90f557..66c348b 100644
@@ -28,6 +28,9 @@ void mmio_ide_init (target_phys_addr_t membase, target_phys_addr_t membase2,
 
 void ide_get_bs(BlockDriverState *bs[], BusState *qbus);
 
+/* ide/core.c */
+void ide_drive_get(DriveInfo **hd, int max_bus);
+
 /* ide/ahci.c */
 void pci_ahci_ide_create_devs(PCIDevice *pci_dev, DriveInfo **hd_table);
 
hw/ide/core.c +14 -0
index 9c91a49..afdf126 100644
@@ -2811,3 +2811,17 @@ const VMStateDescription vmstate_ide_bus = {
         VMSTATE_END_OF_LIST()
     }
 };
+
+void ide_drive_get(DriveInfo **hd, int max_bus)
+{
+    int i;
+
+    if (drive_get_max_bus(IF_IDE) >= max_bus) {
+        fprintf(stderr, "qemu: too many IDE bus: %d\n", max_bus);
+        exit(1);
+    }
+
+    for(i = 0; i < max_bus * MAX_IDE_DEVS; i++) {
+        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
+    }
+}
hw/mips_fulong2e.c +1 -8
index f5ae639..0e90d68 100644
@@ -338,14 +338,7 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
     pci_bus = bonito_init((qemu_irq *)&(env->irq[2]));
 
     /* South bridge */
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
-
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
-        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
-    }
+    ide_drive_get(hd, MAX_IDE_BUS);
 
     via_devfn = vt82c686b_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 0));
     if (via_devfn < 0) {
hw/mips_malta.c +1 -9
index d8baa6d..bf0d76d 100644
@@ -905,15 +905,7 @@ void mips_malta_init (ram_addr_t ram_size,
     pci_bus = gt64120_register(i8259);
 
     /* Southbridge */
-
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
-
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
-        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
-    }
+    ide_drive_get(hd, MAX_IDE_BUS);
 
     piix4_devfn = piix4_init(pci_bus, 80);
     isa_bus_irqs(i8259);
hw/mips_r4k.c +1 -9
index 8feb461..2834a46 100644
@@ -287,15 +287,7 @@ void mips_r4k_init (ram_addr_t ram_size,
     if (nd_table[0].vlan)
         isa_ne2000_init(0x300, 9, &nd_table[0]);
 
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
-
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
-        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
-    }
-
+    ide_drive_get(hd, MAX_IDE_BUS);
     for(i = 0; i < MAX_IDE_BUS; i++)
         isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
                      hd[MAX_IDE_DEVS * i],
hw/pc_piix.c +2 -11
index b3ede89..8ea023d 100644
@@ -129,18 +129,9 @@ static void pc_init1(ram_addr_t ram_size,
             pci_nic_init_nofail(nd, "e1000", NULL);
     }
 
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
-
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
-        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
-    }
-
+    ide_drive_get(hd, MAX_IDE_BUS);
     if (pci_enabled) {
-        PCIDevice *dev;
-        dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
+        PCIDevice *dev = pci_piix3_ide_init(pci_bus, hd, piix3_devfn + 1);
         idebus[0] = qdev_get_child_bus(&dev->qdev, "ide.0");
         idebus[1] = qdev_get_child_bus(&dev->qdev, "ide.1");
     } else {
hw/ppc_newworld.c +2 -9
index b9245f0..86f1cfb 100644
@@ -325,20 +325,13 @@ static void ppc_core99_init (ram_addr_t ram_size,
     for(i = 0; i < nb_nics; i++)
         pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
 
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
+    ide_drive_get(hd, MAX_IDE_BUS);
     dbdma = DBDMA_init(&dbdma_mem_index);
 
     /* We only emulate 2 out of 3 IDE controllers for now */
     ide_mem_index[0] = -1;
-    hd[0] = drive_get(IF_IDE, 0, 0);
-    hd[1] = drive_get(IF_IDE, 0, 1);
     ide_mem_index[1] = pmac_ide_init(hd, pic[0x0d], dbdma, 0x16, pic[0x02]);
-    hd[0] = drive_get(IF_IDE, 1, 0);
-    hd[1] = drive_get(IF_IDE, 1, 1);
-    ide_mem_index[2] = pmac_ide_init(hd, pic[0x0e], dbdma, 0x1a, pic[0x02]);
+    ide_mem_index[2] = pmac_ide_init(&hd[MAX_IDE_DEVS], pic[0x0e], dbdma, 0x1a, pic[0x02]);
 
     /* cuda also initialize ADB */
     if (machine_arch == ARCH_MAC99_U3) {
hw/ppc_oldworld.c +3 -8
index 8a4e088..75a3127 100644
@@ -236,21 +236,16 @@ static void ppc_heathrow_init (ram_addr_t ram_size,
         pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
 
 
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
+    ide_drive_get(hd, MAX_IDE_BUS);
 
     /* First IDE channel is a MAC IDE on the MacIO bus */
-    hd[0] = drive_get(IF_IDE, 0, 0);
-    hd[1] = drive_get(IF_IDE, 0, 1);
     dbdma = DBDMA_init(&dbdma_mem_index);
     ide_mem_index[0] = -1;
     ide_mem_index[1] = pmac_ide_init(hd, pic[0x0D], dbdma, 0x16, pic[0x02]);
 
     /* Second IDE channel is a CMD646 on the PCI bus */
-    hd[0] = drive_get(IF_IDE, 1, 0);
-    hd[1] = drive_get(IF_IDE, 1, 1);
+    hd[0] = hd[MAX_IDE_DEVS];
+    hd[1] = hd[MAX_IDE_DEVS + 1];
     hd[3] = hd[2] = NULL;
     pci_cmd646_ide_init(pci_bus, hd, 0);
 
hw/ppc_prep.c +1 -9
index d86a283..16ca49f 100644
@@ -681,15 +681,7 @@ static void ppc_prep_init (ram_addr_t ram_size,
         }
     }
 
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
-
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
-        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS, i % MAX_IDE_DEVS);
-    }
-
+    ide_drive_get(hd, MAX_IDE_BUS);
     for(i = 0; i < MAX_IDE_BUS; i++) {
         isa_ide_init(ide_iobase[i], ide_iobase2[i], ide_irq[i],
                      hd[2 * i],
hw/sun4u.c +1 -8
index d282324..55ac182 100644
@@ -793,14 +793,7 @@ static void sun4uv_init(ram_addr_t RAM_size,
     for(i = 0; i < nb_nics; i++)
         pci_nic_init_nofail(&nd_table[i], "ne2k_pci", NULL);
 
-    if (drive_get_max_bus(IF_IDE) >= MAX_IDE_BUS) {
-        fprintf(stderr, "qemu: too many IDE bus\n");
-        exit(1);
-    }
-    for(i = 0; i < MAX_IDE_BUS * MAX_IDE_DEVS; i++) {
-        hd[i] = drive_get(IF_IDE, i / MAX_IDE_DEVS,
-                          i % MAX_IDE_DEVS);
-    }
+    ide_drive_get(hd, MAX_IDE_BUS);
 
     pci_cmd646_ide_init(pci_bus, hd, 1);
 
Signature · 1 line
1.7.1.1
#29 lore raw

PATCH 15/26 smbus_eeprom: consolidate smbus eeprom creation

In reply to Isaku Yamahata

consolidate smbus initialization for pc_piix, mips_malta and mips_fulong.

Cc Aurelien Jarno <[email protected]>
Cc Huacai Chen <[email protected]>
---
 hw/mips_fulong2e.c |    9 +--------
 hw/mips_malta.c    |   12 ++----------
 hw/pc_piix.c       |   10 ++--------
 hw/smbus.h         |    3 +++
 hw/smbus_eeprom.c  |   22 ++++++++++++++++++++--
 5 files changed, 28 insertions(+), 28 deletions(-)
hw/mips_fulong2e.c +1 -8
index 0e90d68..420fada 100644
@@ -263,11 +263,9 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
     qemu_irq *cpu_exit_irq;
     int via_devfn;
     PCIBus *pci_bus;
-    uint8_t *eeprom_buf;
     i2c_bus *smbus;
     int i;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    DeviceState *eeprom;
     CPUState *env;
 
     /* init CPUs */
@@ -353,13 +351,8 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
 
     smbus = vt82c686b_pm_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 4),
                               0xeee1, NULL);
-    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-    memcpy(eeprom_buf, eeprom_spd, sizeof(eeprom_spd));
     /* TODO: Populate SPD eeprom data.  */
-    eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-    qdev_prop_set_uint8(eeprom, "address", 0x50);
-    qdev_prop_set_ptr(eeprom, "data", eeprom_buf);
-    qdev_init_nofail(eeprom);
+    smbus_eeprom_init(smbus, 1, eeprom_spd, sizeof(eeprom_spd));
 
     /* init other devices */
     pit = pit_init(0x40, 0);
hw/mips_malta.c +2 -10
index bf0d76d..ed2a483 100644
@@ -770,7 +770,6 @@ void mips_malta_init (ram_addr_t ram_size,
     qemu_irq *i8259;
     qemu_irq *cpu_exit_irq;
     int piix4_devfn;
-    uint8_t *eeprom_buf;
     i2c_bus *smbus;
     int i;
     DriveInfo *dinfo;
@@ -913,15 +912,8 @@ void mips_malta_init (ram_addr_t ram_size,
     usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
     smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
                           NULL, NULL, 0);
-    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-    for (i = 0; i < 8; i++) {
-        /* TODO: Populate SPD eeprom data.  */
-        DeviceState *eeprom;
-        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
-        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
-        qdev_init_nofail(eeprom);
-    }
+    /* TODO: Populate SPD eeprom data.  */
+    smbus_eeprom_init(smbus, 8, NULL, 0);
     pit = pit_init(0x40, 0);
     cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
     DMA_init(0, cpu_exit_irq);
hw/pc_piix.c +2 -8
index 8ea023d..337f2ec 100644
@@ -37,6 +37,7 @@
 #include "sysbus.h"
 #include "arch_init.h"
 #include "blockdev.h"
+#include "smbus.h"
 
 #define MAX_IDE_BUS 2
 
@@ -153,7 +154,6 @@ static void pc_init1(ram_addr_t ram_size,
     }
 
     if (pci_enabled && acpi_enabled) {
-        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
         i2c_bus *smbus;
 
         cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
@@ -162,13 +162,7 @@ static void pc_init1(ram_addr_t ram_size,
         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
                               isa_get_irq(9), *cmos_s3, *smi_irq,
                               kvm_enabled());
-        for (i = 0; i < 8; i++) {
-            DeviceState *eeprom;
-            eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-            qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
-            qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
-            qdev_init_nofail(eeprom);
-        }
+        smbus_eeprom_init(smbus, 8, NULL, 0);
     }
 
     if (i440fx_state) {
hw/smbus.h +3 -0
index 571c52d..a398715 100644
@@ -66,3 +66,6 @@ void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data
 int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
 void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
                        int len);
+
+void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
+                       const uint8_t *eeprom_spd, int size);
hw/smbus_eeprom.c +20 -2
index 52463e0..3634754 100644
@@ -96,7 +96,7 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n)
     return eeprom_receive_byte(dev);
 }
 
-static int smbus_eeprom_init(SMBusDevice *dev)
+static int smbus_eeprom_initfn(SMBusDevice *dev)
 {
     SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
 
@@ -111,7 +111,7 @@ static SMBusDeviceInfo smbus_eeprom_info = {
         DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .init = smbus_eeprom_init,
+    .init = smbus_eeprom_initfn,
     .quick_cmd = eeprom_quick_cmd,
     .send_byte = eeprom_send_byte,
     .receive_byte = eeprom_receive_byte,
@@ -125,3 +125,21 @@ static void smbus_eeprom_register_devices(void)
 }
 
 device_init(smbus_eeprom_register_devices)
+
+void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
+                       const uint8_t *eeprom_spd, int eeprom_spd_size)
+{
+    int i;
+    uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
+    if (eeprom_spd_size > 0) {
+        memcpy(eeprom_buf, eeprom_spd, eeprom_spd_size);
+    }
+
+    for (i = 0; i < nb_eeprom; i++) {
+        DeviceState *eeprom;
+        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
+        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
+        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
+        qdev_init_nofail(eeprom);
+    }
+}
Signature · 1 line
1.7.1.1
Reviewed-by on v1 15/26
#30 lore raw

Re: [Qemu-devel] [PATCH 15/26] smbus_eeprom: consolidate smbus eeprom creation

Quoted 169 lines · Isaku Yamahata

consolidate smbus initialization for pc_piix, mips_malta and mips_fulong.

Cc Aurelien Jarno <[email protected]>
Cc Huacai Chen <[email protected]>
---
 hw/mips_fulong2e.c |    9 +--------
 hw/mips_malta.c    |   12 ++----------
 hw/pc_piix.c       |   10 ++--------
 hw/smbus.h         |    3 +++
 hw/smbus_eeprom.c  |   22 ++++++++++++++++++++--
 5 files changed, 28 insertions(+), 28 deletions(-)
hw/mips_fulong2e.c +1 -8
index 0e90d68..420fada 100644
@@ -263,11 +263,9 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
     qemu_irq *cpu_exit_irq;
     int via_devfn;
     PCIBus *pci_bus;
-    uint8_t *eeprom_buf;
     i2c_bus *smbus;
     int i;
     DriveInfo *hd[MAX_IDE_BUS * MAX_IDE_DEVS];
-    DeviceState *eeprom;
     CPUState *env;
 
     /* init CPUs */
@@ -353,13 +351,8 @@ static void mips_fulong2e_init(ram_addr_t ram_size, const char *boot_device,
 
     smbus = vt82c686b_pm_init(pci_bus, PCI_DEVFN(FULONG2E_VIA_SLOT, 4),
                               0xeee1, NULL);
-    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-    memcpy(eeprom_buf, eeprom_spd, sizeof(eeprom_spd));
     /* TODO: Populate SPD eeprom data.  */
-    eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-    qdev_prop_set_uint8(eeprom, "address", 0x50);
-    qdev_prop_set_ptr(eeprom, "data", eeprom_buf);
-    qdev_init_nofail(eeprom);
+    smbus_eeprom_init(smbus, 1, eeprom_spd, sizeof(eeprom_spd));
 
     /* init other devices */
     pit = pit_init(0x40, 0);
hw/mips_malta.c +2 -10
index bf0d76d..ed2a483 100644
@@ -770,7 +770,6 @@ void mips_malta_init (ram_addr_t ram_size,
     qemu_irq *i8259;
     qemu_irq *cpu_exit_irq;
     int piix4_devfn;
-    uint8_t *eeprom_buf;
     i2c_bus *smbus;
     int i;
     DriveInfo *dinfo;
@@ -913,15 +912,8 @@ void mips_malta_init (ram_addr_t ram_size,
     usb_uhci_piix4_init(pci_bus, piix4_devfn + 2);
     smbus = piix4_pm_init(pci_bus, piix4_devfn + 3, 0x1100, isa_get_irq(9),
                           NULL, NULL, 0);
-    eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
-    for (i = 0; i < 8; i++) {
-        /* TODO: Populate SPD eeprom data.  */
-        DeviceState *eeprom;
-        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
-        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
-        qdev_init_nofail(eeprom);
-    }
+    /* TODO: Populate SPD eeprom data.  */
+    smbus_eeprom_init(smbus, 8, NULL, 0);
     pit = pit_init(0x40, 0);
     cpu_exit_irq = qemu_allocate_irqs(cpu_request_exit, NULL, 1);
     DMA_init(0, cpu_exit_irq);
hw/pc_piix.c +2 -8
index 8ea023d..337f2ec 100644
@@ -37,6 +37,7 @@
 #include "sysbus.h"
 #include "arch_init.h"
 #include "blockdev.h"
+#include "smbus.h"
 
 #define MAX_IDE_BUS 2
 
@@ -153,7 +154,6 @@ static void pc_init1(ram_addr_t ram_size,
     }
 
     if (pci_enabled && acpi_enabled) {
-        uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
         i2c_bus *smbus;
 
         cmos_s3 = qemu_allocate_irqs(pc_cmos_set_s3_resume, rtc_state, 1);
@@ -162,13 +162,7 @@ static void pc_init1(ram_addr_t ram_size,
         smbus = piix4_pm_init(pci_bus, piix3_devfn + 3, 0xb100,
                               isa_get_irq(9), *cmos_s3, *smi_irq,
                               kvm_enabled());
-        for (i = 0; i < 8; i++) {
-            DeviceState *eeprom;
-            eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
-            qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
-            qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
-            qdev_init_nofail(eeprom);
-        }
+        smbus_eeprom_init(smbus, 8, NULL, 0);
     }
 
     if (i440fx_state) {
hw/smbus.h +3 -0
index 571c52d..a398715 100644
@@ -66,3 +66,6 @@ void smbus_write_word(i2c_bus *bus, uint8_t addr, uint8_t command, uint16_t data
 int smbus_read_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data);
 void smbus_write_block(i2c_bus *bus, uint8_t addr, uint8_t command, uint8_t *data,
                        int len);
+
+void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
+                       const uint8_t *eeprom_spd, int size);
hw/smbus_eeprom.c +20 -2
index 52463e0..3634754 100644
@@ -96,7 +96,7 @@ static uint8_t eeprom_read_data(SMBusDevice *dev, uint8_t cmd, int n)
     return eeprom_receive_byte(dev);
 }
 
-static int smbus_eeprom_init(SMBusDevice *dev)
+static int smbus_eeprom_initfn(SMBusDevice *dev)
 {
     SMBusEEPROMDevice *eeprom = (SMBusEEPROMDevice *)dev;
 
@@ -111,7 +111,7 @@ static SMBusDeviceInfo smbus_eeprom_info = {
         DEFINE_PROP_PTR("data", SMBusEEPROMDevice, data),
         DEFINE_PROP_END_OF_LIST(),
     },
-    .init = smbus_eeprom_init,
+    .init = smbus_eeprom_initfn,
     .quick_cmd = eeprom_quick_cmd,
     .send_byte = eeprom_send_byte,
     .receive_byte = eeprom_receive_byte,
@@ -125,3 +125,21 @@ static void smbus_eeprom_register_devices(void)
 }
 
 device_init(smbus_eeprom_register_devices)
+
+void smbus_eeprom_init(i2c_bus *smbus, int nb_eeprom,
+                       const uint8_t *eeprom_spd, int eeprom_spd_size)
+{
+    int i;
+    uint8_t *eeprom_buf = qemu_mallocz(8 * 256); /* XXX: make this persistent */
+    if (eeprom_spd_size > 0) {
+        memcpy(eeprom_buf, eeprom_spd, eeprom_spd_size);
+    }
+
+    for (i = 0; i < nb_eeprom; i++) {
+        DeviceState *eeprom;
+        eeprom = qdev_create((BusState *)smbus, "smbus-eeprom");
+        qdev_prop_set_uint8(eeprom, "address", 0x50 + i);
+        qdev_prop_set_ptr(eeprom, "data", eeprom_buf + (i * 256));
+        qdev_init_nofail(eeprom);
+    }
+}
Signature · 1 line
1.7.1.1
Signature · 2 lines
Aurelien Jarno                          GPG: 1024D/F1BCDB73
[email protected]                 http://www.aurel32.net
#31 lore raw

PATCH 16/26 pc, pc_piix: split out allocating isa irqs

In reply to Isaku Yamahata

Factor out the logic of allocating isa irqs.
This simplifies the pc initialization and will reduce the code duplication of q35 pc initialization.

---
 hw/pc.c      |   16 ++++++++++++++--
 hw/pc.h      |    2 +-
 hw/pc_piix.c |    8 +-------
 3 files changed, 16 insertions(+), 10 deletions(-)
hw/pc.c +14 -2
index 4d67d9f..39c7cf0 100644
@@ -1044,9 +1044,21 @@ void pc_memory_init(ram_addr_t ram_size,
     }
 }
 
-qemu_irq *pc_allocate_cpu_irq(void)
+qemu_irq *pc_isa_irq(IsaIrqState **isa_irq_state_p)
 {
-    return qemu_allocate_irqs(pic_irq_request, NULL, 1);
+    qemu_irq *cpu_irq;
+    qemu_irq *i8259;
+    IsaIrqState *isa_irq_state;
+    qemu_irq *isa_irq;
+
+    cpu_irq = qemu_allocate_irqs(pic_irq_request, NULL, 1);;
+    i8259 = i8259_init(cpu_irq[0]);
+    isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
+    isa_irq_state->i8259 = i8259;
+    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
+
+    *isa_irq_state_p = isa_irq_state;
+    return isa_irq;
 }
 
 void pc_vga_init(PCIBus *pci_bus)
hw/pc.h +1 -1
index feb8a7a..0ee4b89 100644
@@ -135,7 +135,7 @@ void pc_memory_init(ram_addr_t ram_size,
                     const char *initrd_filename,
                     ram_addr_t *below_4g_mem_size_p,
                     ram_addr_t *above_4g_mem_size_p);
-qemu_irq *pc_allocate_cpu_irq(void);
+qemu_irq *pc_isa_irq(IsaIrqState **isa_irq_state_p);
 void pc_vga_init(PCIBus *pci_bus);
 void pc_basic_device_init(qemu_irq *isa_irq,
                           ISADevice **rtc_state);
hw/pc_piix.c +1 -7
index 337f2ec..1ac69ff 100644
@@ -76,9 +76,7 @@ static void pc_init1(ram_addr_t ram_size,
     PCIBus *pci_bus;
     PCII440FXState *i440fx_state;
     int piix3_devfn = -1;
-    qemu_irq *cpu_irq;
     qemu_irq *isa_irq;
-    qemu_irq *i8259;
     qemu_irq *cmos_s3;
     qemu_irq *smi_irq;
     IsaIrqState *isa_irq_state;
@@ -96,14 +94,10 @@ static void pc_init1(ram_addr_t ram_size,
     pc_memory_init(ram_size, kernel_filename, kernel_cmdline, initrd_filename,
                    &below_4g_mem_size, &above_4g_mem_size);
 
-    cpu_irq = pc_allocate_cpu_irq();
-    i8259 = i8259_init(cpu_irq[0]);
-    isa_irq_state = qemu_mallocz(sizeof(*isa_irq_state));
-    isa_irq_state->i8259 = i8259;
+    isa_irq = pc_isa_irq(&isa_irq_state);
     if (pci_enabled) {
         ioapic_init(isa_irq_state);
     }
-    isa_irq = qemu_allocate_irqs(isa_irq_handler, isa_irq_state, 24);
 
     if (pci_enabled) {
         pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
Signature · 1 line
1.7.1.1
#32 lore raw

PATCH 17/26 pc, pc_piix: split out pc nic initialization

In reply to Isaku Yamahata

Factor out pc nic initialization.
This simplifies the pc initialization and will reduce the code duplication of q35 pc initialization.

---
 hw/pc.c      |   15 +++++++++++++++
 hw/pc.h      |    1 +
 hw/pc_piix.c |    9 +--------
 3 files changed, 17 insertions(+), 8 deletions(-)
hw/pc.c +15 -0
index 39c7cf0..dc771a6 100644
@@ -1167,6 +1167,21 @@ void pc_basic_device_init(qemu_irq *isa_irq,
     fdctrl_init_isa(fd);
 }
 
+void pc_nic_init(PCIBus *pci_bus)
+{
+    int i;
+
+    for(i = 0; i < nb_nics; i++) {
+        NICInfo *nd = &nd_table[i];
+
+        if (!pci_bus || (nd->model && strcmp(nd->model, "ne2k_isa") == 0)) {
+            pc_init_ne2k_isa(nd);
+        } else {
+            pci_nic_init_nofail(nd, "e1000", NULL);
+        }
+    }
+}
+
 void pc_pci_device_init(PCIBus *pci_bus)
 {
     int max_bus;
hw/pc.h +1 -0
index 0ee4b89..b70c5f4 100644
@@ -144,6 +144,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size,
                   const char *boot_device,
                   BusState *ide0, BusState *ide1,
                   ISADevice *s);
+void pc_nic_init(PCIBus *pci_bus);
 void pc_pci_device_init(PCIBus *pci_bus);
 
 typedef void (*cpu_set_smm_t)(int smm, void *arg);
hw/pc_piix.c +1 -8
index 1ac69ff..8ee7cab 100644
@@ -115,14 +115,7 @@ static void pc_init1(ram_addr_t ram_size,
     /* init basic PC hardware */
     pc_basic_device_init(isa_irq, &rtc_state);
 
-    for(i = 0; i < nb_nics; i++) {
-        NICInfo *nd = &nd_table[i];
-
-        if (!pci_enabled || (nd->model && strcmp(nd->model, "ne2k_isa") == 0))
-            pc_init_ne2k_isa(nd);
-        else
-            pci_nic_init_nofail(nd, "e1000", NULL);
-    }
+    pc_nic_init(pci_bus);
 
     ide_drive_get(hd, MAX_IDE_BUS);
     if (pci_enabled) {
Signature · 1 line
1.7.1.1
#33 lore raw

PATCH 18/26 ioapic: move ioapic_init() from pc_piix.c to pc.c

In reply to Isaku Yamahata

ioapic isn't piix specific. And q35 pc will use it. So move ioapic_init() from pc_piix.c to common place, pc.c.

---
 hw/pc.c      |   16 ++++++++++++++++
 hw/pc.h      |    2 ++
 hw/pc_piix.c |   16 ----------------
 3 files changed, 18 insertions(+), 16 deletions(-)
hw/pc.c +16 -0
index dc771a6..97d383d 100644
@@ -1192,3 +1192,19 @@ void pc_pci_device_init(PCIBus *pci_bus)
         pci_create_simple(pci_bus, -1, "lsi53c895a");
     }
 }
+
+void ioapic_init(IsaIrqState *isa_irq_state)
+{
+    DeviceState *dev;
+    SysBusDevice *d;
+    unsigned int i;
+
+    dev = qdev_create(NULL, "ioapic");
+    qdev_init_nofail(dev);
+    d = sysbus_from_qdev(dev);
+    sysbus_mmio_map(d, 0, 0xfec00000);
+
+    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
+        isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
+    }
+}
hw/pc.h +2 -0
index b70c5f4..598747d 100644
@@ -150,6 +150,8 @@ void pc_pci_device_init(PCIBus *pci_bus);
 typedef void (*cpu_set_smm_t)(int smm, void *arg);
 void cpu_smm_register(cpu_set_smm_t callback, void *arg);
 
+void ioapic_init(IsaIrqState *isa_irq_state);
+
 /* acpi.c */
 extern int acpi_enabled;
 extern char *acpi_tables;
hw/pc_piix.c +0 -16
index 8ee7cab..f04d58b 100644
@@ -45,22 +45,6 @@ static const int ide_iobase[MAX_IDE_BUS] = { 0x1f0, 0x170 };
 static const int ide_iobase2[MAX_IDE_BUS] = { 0x3f6, 0x376 };
 static const int ide_irq[MAX_IDE_BUS] = { 14, 15 };
 
-static void ioapic_init(IsaIrqState *isa_irq_state)
-{
-    DeviceState *dev;
-    SysBusDevice *d;
-    unsigned int i;
-
-    dev = qdev_create(NULL, "ioapic");
-    qdev_init_nofail(dev);
-    d = sysbus_from_qdev(dev);
-    sysbus_mmio_map(d, 0, 0xfec00000);
-
-    for (i = 0; i < IOAPIC_NUM_PINS; i++) {
-        isa_irq_state->ioapic[i] = qdev_get_gpio_in(dev, i);
-    }
-}
-
 /* PC hardware initialisation */
 static void pc_init1(ram_addr_t ram_size,
                      const char *boot_device,
Signature · 1 line
1.7.1.1
#34 lore raw

PATCH 19/26 pc/piix_pci: factor out smram/pam logic

In reply to Isaku Yamahata

Factor out smram/pam logic for later use. Which will be used by q35 too.

---
 Makefile.target |    2 +-
 hw/pam.c        |  128 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/pam.h        |   96 +++++++++++++++++++++++++++++++++++++++++
 hw/piix_pci.c   |   71 +++++--------------------------
 4 files changed, 236 insertions(+), 61 deletions(-)
 create mode 100644 hw/pam.c
 create mode 100644 hw/pam.h
Makefile.target +1 -1
index f0df98e..d57d250 100644
@@ -214,7 +214,7 @@ obj-$(CONFIG_KVM) += ivshmem.o
 # Hardware support
 obj-i386-y += vga.o
 obj-i386-y += mc146818rtc.o i8259.o pc.o
-obj-i386-y += cirrus_vga.o apic.o ioapic.o piix_pci.o
+obj-i386-y += cirrus_vga.o apic.o ioapic.o piix_pci.o pam.o
 obj-i386-y += vmport.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
 obj-i386-y += debugcon.o multiboot.o
hw/pam.c new file +128 -0

128 lines not on this page · raw message

hw/pam.h new file +96 -0

96 lines not on this page · raw message

hw/piix_pci.c +11 -60

114 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#35 lore raw

PATCH 20/26 pc, i440fx: simply i440fx initialization

In reply to Isaku Yamahata

simply i440fx initialization by eliminating
i440fx_init_memory_mappings().

---
 hw/pc.h       |    2 +-
 hw/pc_piix.c  |    8 +-------
 hw/piix_pci.c |   15 ++++++---------
 3 files changed, 8 insertions(+), 17 deletions(-)
hw/pc.h +1 -1
index 598747d..d382bb6 100644
@@ -178,7 +178,7 @@ int pcspk_audio_init(qemu_irq *pic);
 struct PCII440FXState;
 typedef struct PCII440FXState PCII440FXState;
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
+PCIBus *i440fx_init(int *piix_devfn, qemu_irq *pic, ram_addr_t ram_size);
 void i440fx_init_memory_mappings(PCII440FXState *d);
 
 /* piix4.c */
hw/pc_piix.c +1 -7
index f04d58b..a3697e7 100644
@@ -58,7 +58,6 @@ static void pc_init1(ram_addr_t ram_size,
     int i;
     ram_addr_t below_4g_mem_size, above_4g_mem_size;
     PCIBus *pci_bus;
-    PCII440FXState *i440fx_state;
     int piix3_devfn = -1;
     qemu_irq *isa_irq;
     qemu_irq *cmos_s3;
@@ -84,10 +83,9 @@ static void pc_init1(ram_addr_t ram_size,
     }
 
     if (pci_enabled) {
-        pci_bus = i440fx_init(&i440fx_state, &piix3_devfn, isa_irq, ram_size);
+        pci_bus = i440fx_init(&piix3_devfn, isa_irq, ram_size);
     } else {
         pci_bus = NULL;
-        i440fx_state = NULL;
         isa_bus_new(NULL);
     }
     isa_bus_irqs(isa_irq);
@@ -136,10 +134,6 @@ static void pc_init1(ram_addr_t ram_size,
         smbus_eeprom_init(smbus, 8, NULL, 0);
     }
 
-    if (i440fx_state) {
-        i440fx_init_memory_mappings(i440fx_state);
-    }
-
     if (pci_enabled) {
         pc_pci_device_init(pci_bus);
     }
hw/piix_pci.c +6 -9
index f619162..151353c 100644
@@ -84,11 +84,6 @@ static void i440fx_set_smm(int val, void *arg)
     smram_set_smm(&d->pam, val, d->dev.config[I440FX_SMRAM]);
 }
 
-void i440fx_init_memory_mappings(PCII440FXState *d)
-{
-    pam_init_memory_mappings(&d->pam);
-}
-
 static void i440fx_write_config(PCIDevice *dev,
                                 uint32_t address, uint32_t val, int len)
 {
@@ -166,15 +161,17 @@ static int i440fx_initfn(PCIDevice *dev)
     d->dev.config[I440FX_SMRAM] = 0x02;
 
     cpu_smm_register(&i440fx_set_smm, d);
+    pam_init_memory_mappings(&d->pam);
     return 0;
 }
 
-PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size)
+PCIBus *i440fx_init(int *piix3_devfn, qemu_irq *pic, ram_addr_t ram_size)
 {
     DeviceState *dev;
     PCIBus *b;
     PCIDevice *d;
     I440FXState *s;
+    PCII440FXState *i440fx_state;
     PIIX3State *piix3;
 
     dev = qdev_create(NULL, "i440FX-pcihost");
@@ -184,20 +181,20 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *
     qdev_init_nofail(dev);
 
     d = pci_create_simple(b, 0, "i440FX");
-    *pi440fx_state = DO_UPCAST(PCII440FXState, dev, d);
+    i440fx_state = DO_UPCAST(PCII440FXState, dev, d);
 
     piix3 = DO_UPCAST(PIIX3State, dev,
                       pci_create_simple_multifunction(b, -1, true, "PIIX3"));
     piix3->pic = pic;
     pci_bus_irqs(b, piix3_set_irq, pci_slot_get_pirq, piix3, 4);
-    (*pi440fx_state)->piix3 = piix3;
+    i440fx_state->piix3 = piix3;
 
     *piix3_devfn = piix3->dev.devfn;
 
     ram_size = ram_size / 8 / 1024 / 1024;
     if (ram_size > 255)
         ram_size = 255;
-    (*pi440fx_state)->dev.config[0x57]=ram_size;
+    i440fx_state->dev.config[0x57]=ram_size;
 
     return b;
 }
Signature · 1 line
1.7.1.1
#36 lore raw

PATCH 21/26 acpi, acpi_piix: factor out PM_TMR logic

In reply to Isaku Yamahata

factor out PM_TMR logic. Later This will be used by ich9 acpi.

---
 hw/acpi.c       |   45 +++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi.h       |   24 ++++++++++++++++++++++++
 hw/acpi_piix4.c |   45 ++++++++++++---------------------------------
 3 files changed, 81 insertions(+), 33 deletions(-)
hw/acpi.c +45 -0
index e9bcf18..bd987e0 100644
@@ -217,3 +217,48 @@ out:
     }
     return -1;
 }
+
+/* ACPI PM_TMR */
+void acpi_pm_tmr_update(ACPIPMTimer *tmr, bool enable)
+{
+    int64_t expire_time;
+
+    /* schedule a timer interruption if needed */
+    if (enable) {
+        expire_time = muldiv64(tmr->overflow_time, get_ticks_per_sec(),
+                               PM_TIMER_FREQUENCY);
+        qemu_mod_timer(tmr->timer, expire_time);
+    } else {
+        qemu_del_timer(tmr->timer);
+    }
+}
+
+void acpi_pm_tmr_calc_overflow_time(ACPIPMTimer *tmr)
+{
+    int64_t d = acpi_pm_tmr_get_clock();
+    tmr->overflow_time = (d + 0x800000LL) & ~0x7fffffLL;
+}
+
+uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr)
+{
+    uint32_t d = acpi_pm_tmr_get_clock();;
+    return d & 0xffffff;
+}
+
+static void acpi_pm_tmr_timer(void *opaque)
+{
+    ACPIPMTimer *tmr = opaque;
+    tmr->update_sci(tmr);
+}
+
+void acpi_pm_tmr_init(ACPIPMTimer *tmr, acpi_update_sci_fn update_sci)
+{
+    tmr->update_sci = update_sci;
+    tmr->timer = qemu_new_timer(vm_clock, acpi_pm_tmr_timer, tmr);
+}
+
+void acpi_pm_tmr_reset(ACPIPMTimer *tmr)
+{
+    tmr->overflow_time = 0;
+    qemu_del_timer(tmr->timer);
+}
hw/acpi.h +24 -0
index 5949958..1f9132f 100644
@@ -74,5 +74,29 @@
 #define ACPI_BITMASK_ARB_DISABLE                0x0001
 
 /* PM_TMR */
+struct ACPIPMTimer;
+typedef struct ACPIPMTimer ACPIPMTimer;
+
+typedef void (*acpi_update_sci_fn)(ACPIPMTimer *tmr);
+
+struct ACPIPMTimer {
+    QEMUTimer *timer;
+    int64_t overflow_time;
+
+    acpi_update_sci_fn update_sci;
+};
+
+void acpi_pm_tmr_update(ACPIPMTimer *tmr, bool enable);
+void acpi_pm_tmr_calc_overflow_time(ACPIPMTimer *tmr);
+uint32_t acpi_pm_tmr_get(ACPIPMTimer *tmr);
+void acpi_pm_tmr_init(ACPIPMTimer *tmr, acpi_update_sci_fn update_sci);
+void acpi_pm_tmr_reset(ACPIPMTimer *tmr);
+
+#include "qemu-timer.h"
+static inline int64_t acpi_pm_tmr_get_clock(void)
+{
+    return muldiv64(qemu_get_clock(vm_clock), PM_TIMER_FREQUENCY,
+                    get_ticks_per_sec());
+}
 
 #endif /* !QEMU_HW_ACPI_H */
hw/acpi_piix4.c +12 -33

102 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#37 lore raw

Re: [Qemu-devel] [PATCH 21/26] acpi, acpi_piix: factor out PM_TMR logic

Quoted 1 line · Isaku Yamahata

factor out PM_TMR logic. Later This will be used by ich9 acpi.

Please also refactor vt82c686.c.

#38 lore raw

PATCH 22/26 acpi, acpi_piix: factor out PM1a EVT logic

In reply to Isaku Yamahata

factor out ACPI PM1a EVT logic.
Later this will be used by ich9 acpi.

---
 hw/acpi.c       |   37 +++++++++++++++++++++++++++++++++++++
 hw/acpi.h       |   13 +++++++++++++
 hw/acpi_piix4.c |   52 ++++++++++++++++------------------------------------
 3 files changed, 66 insertions(+), 36 deletions(-)
hw/acpi.c +37 -0
index bd987e0..158f30d 100644
@@ -15,6 +15,7 @@
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, see <http://www.gnu.org/licenses/>
  */
+#include "sysemu.h"
 #include "hw.h"
 #include "pc.h"
 #include "acpi.h"
@@ -218,6 +219,42 @@ out:
     return -1;
 }
 
+/* ACPI PM1a EVT */
+uint16_t acpi_pm1_evt_get_sts(ACPIPM1EVT *pm1, int64_t overflow_time)
+{
+    int64_t d = acpi_pm_tmr_get_clock();
+    if (d >= overflow_time) {
+        pm1->sts |= ACPI_BITMASK_TIMER_STATUS;
+    }
+    return pm1->sts;
+}
+
+void acpi_pm1_evt_write_sts(ACPIPM1EVT *pm1, ACPIPMTimer *tmr, uint16_t val)
+{
+    uint16_t pm1_sts = acpi_pm1_evt_get_sts(pm1, tmr->overflow_time);
+    if (pm1_sts & val & ACPI_BITMASK_TIMER_STATUS) {
+        /* if TMRSTS is reset, then compute the new overflow time */
+        acpi_pm_tmr_calc_overflow_time(tmr);
+    }
+    pm1->sts &= ~val;
+}
+
+void acpi_pm1_evt_power_down(ACPIPM1EVT *pm1, ACPIPMTimer *tmr)
+{
+    if (!pm1) {
+        qemu_system_shutdown_request();
+    } else if (pm1->en & ACPI_BITMASK_POWER_BUTTON_ENABLE) {
+        pm1->sts |= ACPI_BITMASK_POWER_BUTTON_STATUS;
+        tmr->update_sci(tmr);
+    }
+}
+
+void acpi_pm1_evt_reset(ACPIPM1EVT *pm1)
+{
+    pm1->sts = 0;
+    pm1->en = 0;
+}
+
 /* ACPI PM_TMR */
 void acpi_pm_tmr_update(ACPIPMTimer *tmr, bool enable)
 {
hw/acpi.h +13 -0
index 1f9132f..f79939f 100644
@@ -99,4 +99,17 @@ static inline int64_t acpi_pm_tmr_get_clock(void)
                     get_ticks_per_sec());
 }
 
+/* PM1a_EVT: piix and ich9 don't implement PM1b. */
+struct ACPIPM1EVT
+{
+    uint16_t sts;
+    uint16_t en;
+};
+typedef struct ACPIPM1EVT ACPIPM1EVT;
+
+uint16_t acpi_pm1_evt_get_sts(ACPIPM1EVT *pm1, int64_t overflow_time);
+void acpi_pm1_evt_write_sts(ACPIPM1EVT *pm1, ACPIPMTimer *tmr, uint16_t val);
+void acpi_pm1_evt_power_down(ACPIPM1EVT *pm1, ACPIPMTimer *tmr);
+void acpi_pm1_evt_reset(ACPIPM1EVT *pm1);
+
 #endif /* !QEMU_HW_ACPI_H */
hw/acpi_piix4.c +16 -36

109 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#39 lore raw

Re: [Qemu-devel] [PATCH 22/26] acpi, acpi_piix: factor out PM1a EVT logic

Quoted 2 lines · Isaku Yamahata

factor out ACPI PM1a EVT logic.
Later this will be used by ich9 acpi.

Also this logic is duplicated in vt82c686.c.

#40 lore raw

PATCH 23/26 acpi, acpi_piix: factor out PM1_CNT logic

In reply to Isaku Yamahata

factor out ACPI PM1_CNT logic. This will be used by ich9 acpi.

---
 hw/acpi.c       |   49 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/acpi.h       |   14 ++++++++++++++
 hw/acpi_piix4.c |   40 ++++++----------------------------------
 3 files changed, 69 insertions(+), 34 deletions(-)
hw/acpi.c +49 -0
index 158f30d..24c878a 100644
@@ -299,3 +299,52 @@ void acpi_pm_tmr_reset(ACPIPMTimer *tmr)
     tmr->overflow_time = 0;
     qemu_del_timer(tmr->timer);
 }
+
+/* ACPI PM1aCNT */
+void acpi_pm1_cnt_init(ACPIPM1CNT *pm1_cnt, qemu_irq cmos_s3)
+{
+    pm1_cnt->cmos_s3 = cmos_s3;
+}
+
+void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val)
+{
+    pm1_cnt->cnt = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
+
+    if (val & ACPI_BITMASK_SLEEP_ENABLE) {
+        /* change suspend type */
+        uint16_t sus_typ = (val >> 10) & 7;
+        switch(sus_typ) {
+        case 0: /* soft power off */
+            qemu_system_shutdown_request();
+            break;
+        case 1:
+            /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
+               Pretend that resume was caused by power button */
+            pm1a->sts |=
+                (ACPI_BITMASK_WAKE_STATUS | ACPI_BITMASK_POWER_BUTTON_STATUS);
+            qemu_system_reset_request();
+            qemu_irq_raise(pm1_cnt->cmos_s3);
+        default:
+            break;
+        }
+    }
+}
+
+void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,
+                         bool sci_enable, bool sci_disable)
+{
+    /* ACPI specs 3.0, 4.7.2.5 */
+    if (sci_enable) {
+        pm1_cnt->cnt |= ACPI_BITMASK_SCI_ENABLE;
+    } else if (sci_disable) {
+        pm1_cnt->cnt &= ~ACPI_BITMASK_SCI_ENABLE;
+    }
+}
+
+void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt)
+{
+    pm1_cnt->cnt = 0;
+    if (pm1_cnt->cmos_s3) {
+        qemu_irq_lower(pm1_cnt->cmos_s3);
+    }
+}
hw/acpi.h +14 -0
index f79939f..ab70c00 100644
@@ -112,4 +112,18 @@ void acpi_pm1_evt_write_sts(ACPIPM1EVT *pm1, ACPIPMTimer *tmr, uint16_t val);
 void acpi_pm1_evt_power_down(ACPIPM1EVT *pm1, ACPIPMTimer *tmr);
 void acpi_pm1_evt_reset(ACPIPM1EVT *pm1);
 
+/* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
+struct ACPIPM1CNT {
+    uint16_t cnt;
+
+    qemu_irq cmos_s3;
+};
+typedef struct ACPIPM1CNT ACPIPM1CNT;
+
+void acpi_pm1_cnt_init(ACPIPM1CNT *pm1_cnt, qemu_irq cmos_s3);
+void acpi_pm1_cnt_write(ACPIPM1EVT *pm1a, ACPIPM1CNT *pm1_cnt, uint16_t val);
+void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,
+                         bool sci_enable, bool sci_disable);
+void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt);
+
 #endif /* !QEMU_HW_ACPI_H */
hw/acpi_piix4.c +6 -34
index 5b4eef5..ce86ee3 100644
@@ -55,7 +55,7 @@ typedef struct PIIX4PMState {
     PCIDevice dev;
     IORange ioport;
     ACPIPM1EVT pm1a;
-    uint16_t pmcntrl;
+    ACPIPM1CNT pm1_cnt;
 
     APMState apm;
 
@@ -65,7 +65,6 @@ typedef struct PIIX4PMState {
     uint32_t smb_io_base;
 
     qemu_irq irq;
-    qemu_irq cmos_s3;
     qemu_irq smi_irq;
     int kvm_enabled;
 
@@ -124,30 +123,7 @@ static void pm_ioport_write(IORange *ioport, uint64_t addr, unsigned width,
         pm_update_sci(s);
         break;
     case 0x04:
-        {
-            int sus_typ;
-            s->pmcntrl = val & ~(ACPI_BITMASK_SLEEP_ENABLE);
-            if (val & ACPI_BITMASK_SLEEP_ENABLE) {
-                /* change suspend type */
-                sus_typ = (val >> 10) & 7;
-                switch(sus_typ) {
-                case 0: /* soft power off */
-                    qemu_system_shutdown_request();
-                    break;
-                case 1:
-                    /* ACPI_BITMASK_WAKE_STATUS should be set on resume.
-                       Pretend that resume was caused by power button */
-                    s->pm1a.sts |= (ACPI_BITMASK_WAKE_STATUS |
-                                    ACPI_BITMASK_POWER_BUTTON_STATUS);
-                    qemu_system_reset_request();
-                    if (s->cmos_s3) {
-                        qemu_irq_raise(s->cmos_s3);
-                    }
-                default:
-                    break;
-                }
-            }
-        }
+        acpi_pm1_cnt_write(&s->pm1a, &s->pm1_cnt, val);
         break;
     default:
         break;
@@ -169,7 +145,7 @@ static void pm_ioport_read(IORange *ioport, uint64_t addr, unsigned width,
         val = s->pm1a.en;
         break;
     case 0x04:
-        val = s->pmcntrl;
+        val = s->pm1_cnt.cnt;
         break;
     case 0x08:
         val = acpi_pm_tmr_get(&s->tmr);
@@ -192,11 +168,7 @@ static void apm_ctrl_changed(uint32_t val, void *arg)
     PIIX4PMState *s = arg;
 
     /* ACPI specs 3.0, 4.7.2.5 */
-    if (val == ACPI_ENABLE) {
-        s->pmcntrl |= ACPI_BITMASK_SCI_ENABLE;
-    } else if (val == ACPI_DISABLE) {
-        s->pmcntrl &= ~ACPI_BITMASK_SCI_ENABLE;
-    }
+    acpi_pm1_cnt_update(&s->pm1_cnt, val == ACPI_ENABLE, val == ACPI_DISABLE);
 
     if (s->dev.config[0x5b] & (1 << 1)) {
         if (s->smi_irq) {
@@ -275,7 +247,7 @@ static const VMStateDescription vmstate_acpi = {
         VMSTATE_PCI_DEVICE(dev, PIIX4PMState),
         VMSTATE_UINT16(pm1a.sts, PIIX4PMState),
         VMSTATE_UINT16(pm1a.en, PIIX4PMState),
-        VMSTATE_UINT16(pmcntrl, PIIX4PMState),
+        VMSTATE_UINT16(pm1_cnt.cnt, PIIX4PMState),
         VMSTATE_STRUCT(apm, PIIX4PMState, 0, vmstate_apm, APMState),
         VMSTATE_TIMER(tmr.timer, PIIX4PMState),
         VMSTATE_INT64(tmr.overflow_time, PIIX4PMState),
@@ -395,7 +367,7 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
 
     s = DO_UPCAST(PIIX4PMState, dev, dev);
     s->irq = sci_irq;
-    s->cmos_s3 = cmos_s3;
+    acpi_pm1_cnt_init(&s->pm1_cnt, cmos_s3);
     s->smi_irq = smi_irq;
     s->kvm_enabled = kvm_enabled;
 
Signature · 1 line
1.7.1.1
#41 lore raw

PATCH 24/26 acpi, acpi_piix: factor out GPE logic

In reply to Isaku Yamahata

factor out ACPI GPE logic. Later it will be used by ICH9 ACPI.

---
 hw/acpi.c       |   66 ++++++++++++++++++++++++++++++++++++++
 hw/acpi.h       |   17 ++++++++++
 hw/acpi_piix4.c |   95 ++++++++++++++----------------------------------------
 3 files changed, 108 insertions(+), 70 deletions(-)
hw/acpi.c +66 -0
index 24c878a..315ea25 100644
@@ -348,3 +348,69 @@ void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt)
         qemu_irq_lower(pm1_cnt->cmos_s3);
     }
 }
+
+/* ACPI GPE */
+void acpi_gpe_init(ACPIGPE *gpe, uint8_t len)
+{
+    gpe->len = len;
+    gpe->sts = qemu_mallocz(len / 2);
+    gpe->en = qemu_mallocz(len / 2);
+}
+
+void acpi_gpe_blk(ACPIGPE *gpe, uint32_t blk)
+{
+    gpe->blk = blk;
+}
+
+void acpi_gpe_reset(ACPIGPE *gpe)
+{
+    memset(gpe->sts, 0, gpe->len / 2);
+    memset(gpe->en, 0, gpe->len / 2);
+}
+
+static uint8_t *acpi_gpe_ioport_get_ptr(ACPIGPE *gpe, uint32_t addr)
+{
+    uint8_t *cur = NULL;
+
+    if (addr < gpe->len / 2) {
+        cur = gpe->sts + addr;
+    } else if (addr < gpe->len) {
+        cur = gpe->en + addr;
+    } else {
+        abort();
+    }
+
+    return cur;
+}
+
+void acpi_gpe_ioport_writeb(ACPIGPE *gpe, uint32_t addr, uint32_t val)
+{
+    uint8_t *cur;
+
+    addr -= gpe->blk;
+    cur = acpi_gpe_ioport_get_ptr(gpe, addr);
+    if (addr < gpe->len / 2) {
+        /* GPE_STS */
+        *cur = (*cur) & ~val;
+    } else if (addr < gpe->len) {
+        /* GPE_EN */
+        *cur = val;
+    } else {
+        abort();
+    }
+}
+
+uint32_t acpi_gpe_ioport_readb(ACPIGPE *gpe, uint32_t addr)
+{
+    uint8_t *cur;
+    uint32_t val;
+
+    addr -= gpe->blk;
+    cur = acpi_gpe_ioport_get_ptr(gpe, addr);
+    val = 0;
+    if (cur != NULL) {
+        val = *cur;
+    }
+
+    return val;
+}
hw/acpi.h +17 -0
index ab70c00..0c666a8 100644
@@ -126,4 +126,21 @@ void acpi_pm1_cnt_update(ACPIPM1CNT *pm1_cnt,
                          bool sci_enable, bool sci_disable);
 void acpi_pm1_cnt_reset(ACPIPM1CNT *pm1_cnt);
 
+/* GPE0 */
+struct ACPIGPE {
+    uint32_t blk;
+    uint8_t len;
+
+    uint8_t *sts;
+    uint8_t *en;
+};
+typedef struct ACPIGPE ACPIGPE;
+
+void acpi_gpe_init(ACPIGPE *gpe, uint8_t len);
+void acpi_gpe_blk(ACPIGPE *gpe, uint32_t blk);
+void acpi_gpe_reset(ACPIGPE *gpe);
+
+void acpi_gpe_ioport_writeb(ACPIGPE *gpe, uint32_t addr, uint32_t val);
+uint32_t acpi_gpe_ioport_readb(ACPIGPE *gpe, uint32_t addr);
+
 #endif /* !QEMU_HW_ACPI_H */
hw/acpi_piix4.c +25 -70

178 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#42 lore raw

Re: [Qemu-devel] [PATCH 24/26] acpi, acpi_piix: factor out GPE logic

Quoted 2 lines · Isaku Yamahata

factor out ACPI GPE logic. Later it will be used by ICH9 ACPI.

I think this patch is causing qemu-kvm failures on migration:
(gdb) bt

#0  0x000000000049aff4 in qemu_put_be16s (f=0x1a74490, pv=0x2c02580, size=2) at hw/hw.h:108
#1  put_uint16 (f=0x1a74490, pv=0x2c02580, size=2) at savevm.c:855
#2  0x000000000049c3e4 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0b00, opaque=0x1842ef0) at savevm.c:1436
#3  0x000000000049c3b6 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0aa0, opaque=0x1842b90) at savevm.c:1434
#4  0x000000000049c6f1 in vmstate_save (mon=<value optimized out>, f=0x1a74490) at savevm.c:1459
#5  qemu_savevm_state_complete (mon=<value optimized out>, f=0x1a74490) at savevm.c:1600
#6  0x000000000049455a in migrate_fd_put_ready (opaque=0x1847890) at migration.c:383
#7  0x00000000004ce2eb in qemu_run_timers (clock=<value optimized out>) at qemu-timer.c:505
#8  0x00000000004ce806 in qemu_run_all_timers () at qemu-timer.c:619
#9  0x0000000000419463 in main_loop_wait (nonblocking=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:1339
#10 0x0000000000433927 in kvm_main_loop () at /build/home/tlv/akivity/qemu-kvm/qemu-kvm.c:1590
#11 0x000000000041a3a6 in main_loop (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>)
    at /build/home/tlv/akivity/qemu-kvm/vl.c:1369

#12 main (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:3257

The vmstate being migrated is "gpe".

Quoted 15 lines
hw/acpi_piix4.c +11 -0
+#define VMSTATE_GPE_ARRAY(_field, _state)                            \
+ {                                                                   \
+     .name       = (stringify(_field)),                              \
+     .version_id = 0,                                                \
+     .num        = GPE_LEN,                                          \
+     .info       =&vmstate_info_uint16,                             \
+     .size       = sizeof(uint16_t),                                 \
+     .flags      = VMS_ARRAY | VMS_POINTER,                          \
+     .offset     = vmstate_offset_pointer(_state, _field, uint8_t),  \
+ }
+
  static const VMStateDescription vmstate_gpe = {
      .name = "gpe",
      .version_id = 1,

hw/acpi_piix4.c static int vmstate_acpi_post_load(void *opaque, int version_id) · line 233

Quoted 10 lines
hw/acpi_piix4.c +2 -2
      .minimum_version_id = 1,
      .minimum_version_id_old = 1,
      .fields      = (VMStateField []) {
-        VMSTATE_UINT16(sts, struct gpe_regs),
-        VMSTATE_UINT16(en, struct gpe_regs),
+        VMSTATE_GPE_ARRAY(sts, ACPIGPE),
+        VMSTATE_GPE_ARRAY(en, ACPIGPE),
          VMSTATE_END_OF_LIST()
      }
  };

I'm no vmstate expert, but this does look odd. Why both VMS_ARRAY and VMS_POINTER? aren't we trying to save/restore a simple 16-bit value? Or at least we did before this patch.

Signature · 1 line
error compiling committee.c: too many arguments to function
#43 lore raw

Re: [Qemu-devel] [PATCH 24/26] acpi, acpi_piix: factor out GPE logic

Quoted 57 lines · Avi Kivity
Quoted 2 lines · Isaku Yamahata

factor out ACPI GPE logic. Later it will be used by ICH9 ACPI.

I think this patch is causing qemu-kvm failures on migration:
(gdb) bt
#0 0x000000000049aff4 in qemu_put_be16s (f=0x1a74490, pv=0x2c02580, size=2) at hw/hw.h:108
#1 put_uint16 (f=0x1a74490, pv=0x2c02580, size=2) at savevm.c:855 #2 0x000000000049c3e4 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0b00, opaque=0x1842ef0) at savevm.c:1436
#3 0x000000000049c3b6 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0aa0, opaque=0x1842b90) at savevm.c:1434
#4 0x000000000049c6f1 in vmstate_save (mon=<value optimized out>, f=0x1a74490) at savevm.c:1459
#5 qemu_savevm_state_complete (mon=<value optimized out>, f=0x1a74490) at savevm.c:1600
#6 0x000000000049455a in migrate_fd_put_ready (opaque=0x1847890) at migration.c:383
#7 0x00000000004ce2eb in qemu_run_timers (clock=<value optimized out>) at qemu-timer.c:505
#8 0x00000000004ce806 in qemu_run_all_timers () at qemu-timer.c:619 #9 0x0000000000419463 in main_loop_wait (nonblocking=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:1339
#10 0x0000000000433927 in kvm_main_loop () at /build/home/tlv/akivity/qemu-kvm/qemu-kvm.c:1590
#11 0x000000000041a3a6 in main_loop (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>)

    at /build/home/tlv/akivity/qemu-kvm/vl.c:1369

#12 main (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:3257

The vmstate being migrated is "gpe".

Quoted 21 lines
(quoted diff) +12 -2
+#define VMSTATE_GPE_ARRAY(_field, _state)                            \
+ {                                                                   \
+     .name       = (stringify(_field)),                              \
+     .version_id = 0,                                                \
+     .num        = GPE_LEN,                                          \
+     .info       =&vmstate_info_uint16,                             \
+     .size       = sizeof(uint16_t),                                 \
+     .flags      = VMS_ARRAY | VMS_POINTER,                          \
+     .offset     = vmstate_offset_pointer(_state, _field, uint8_t),  \
+ }
+
  static const VMStateDescription vmstate_gpe = {
      .name = "gpe",
      .version_id = 1,
      .minimum_version_id = 1,
      .minimum_version_id_old = 1,
      .fields      = (VMStateField []) {
-        VMSTATE_UINT16(sts, struct gpe_regs),
-        VMSTATE_UINT16(en, struct gpe_regs),
+        VMSTATE_GPE_ARRAY(sts, ACPIGPE),
Quoted 8 lines
Quoted 4 lines

+ VMSTATE_GPE_ARRAY(en, ACPIGPE),

          VMSTATE_END_OF_LIST()
      }

};

I'm no vmstate expert, but this does look odd. Why both VMS_ARRAY and VMS_POINTER? aren't we trying to save/restore a simple 16-bit value? Or at least we did before this patch.

That's right. the difference is, the new member type became uint8_t*. Does the following help?

hw/acpi_piix4.c +1 -2
index 96f5222..3a8fece 100644
@@ -214,10 +214,9 @@ static int vmstate_acpi_post_load(void *opaque, int version_id)
  {                                                                   \
      .name       = (stringify(_field)),                              \
      .version_id = 0,                                                \
-     .num        = GPE_LEN,                                          \
      .info       = &vmstate_info_uint16,                             \
      .size       = sizeof(uint16_t),                                 \
-     .flags      = VMS_ARRAY | VMS_POINTER,                          \
+     .flags      = VMS_SINGLE | VMS_POINTER,                         \
      .offset     = vmstate_offset_pointer(_state, _field, uint8_t),  \
  }
 
Signature · 1 line
yamahata
#44 lore raw

Re: [Qemu-devel] [PATCH 24/26] acpi, acpi_piix: factor out GPE logic

Quoted 63 lines · Isaku Yamahata
Quoted 62 lines · Avi Kivity
Quoted 2 lines · Isaku Yamahata

factor out ACPI GPE logic. Later it will be used by ICH9 ACPI.

I think this patch is causing qemu-kvm failures on migration:
(gdb) bt
#0 0x000000000049aff4 in qemu_put_be16s (f=0x1a74490, pv=0x2c02580, size=2) at hw/hw.h:108
#1 put_uint16 (f=0x1a74490, pv=0x2c02580, size=2) at savevm.c:855 #2 0x000000000049c3e4 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0b00, opaque=0x1842ef0) at savevm.c:1436
#3 0x000000000049c3b6 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0aa0, opaque=0x1842b90) at savevm.c:1434
#4 0x000000000049c6f1 in vmstate_save (mon=<value optimized out>, f=0x1a74490) at savevm.c:1459
#5 qemu_savevm_state_complete (mon=<value optimized out>, f=0x1a74490) at savevm.c:1600
#6 0x000000000049455a in migrate_fd_put_ready (opaque=0x1847890) at migration.c:383
#7 0x00000000004ce2eb in qemu_run_timers (clock=<value optimized out>) at qemu-timer.c:505
#8 0x00000000004ce806 in qemu_run_all_timers () at qemu-timer.c:619 #9 0x0000000000419463 in main_loop_wait (nonblocking=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:1339
#10 0x0000000000433927 in kvm_main_loop () at /build/home/tlv/akivity/qemu-kvm/qemu-kvm.c:1590
#11 0x000000000041a3a6 in main_loop (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>)

     at /build/home/tlv/akivity/qemu-kvm/vl.c:1369
 #12 main (argc=<value optimized out>, argv=<value optimized out>,
 envp=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:3257

The vmstate being migrated is "gpe".

Quoted 25 lines
 +#define VMSTATE_GPE_ARRAY(_field, _state)                            \
 + {                                                                   \
 +     .name       = (stringify(_field)),                              \
 +     .version_id = 0,                                                \
 +     .num        = GPE_LEN,                                          \
 +     .info       =&vmstate_info_uint16,                             \
 +     .size       = sizeof(uint16_t),                                 \
 +     .flags      = VMS_ARRAY | VMS_POINTER,                          \
 +     .offset     = vmstate_offset_pointer(_state, _field, uint8_t),  \
 + }
 +
   static const VMStateDescription vmstate_gpe = {
       .name = "gpe",
       .version_id = 1,
       .minimum_version_id = 1,
       .minimum_version_id_old = 1,
       .fields      = (VMStateField []) {
 -        VMSTATE_UINT16(sts, struct gpe_regs),
 -        VMSTATE_UINT16(en, struct gpe_regs),
 +        VMSTATE_GPE_ARRAY(sts, ACPIGPE),
 +        VMSTATE_GPE_ARRAY(en, ACPIGPE),
           VMSTATE_END_OF_LIST()
       }

};

Quoted 7 lines
Quoted 3 lines

I'm no vmstate expert, but this does look odd. Why both VMS_ARRAY and VMS_POINTER? aren't we trying to save/restore a simple 16-bit value? Or at least we did before this patch.

That's right. the difference is, the new member type became uint8_t*. Does the following help?

Unforunately not. The core is very similar though:

#0  0x000000000049aff4 in qemu_put_be16s (f=0x2427490, pv=0x1ae7580, size=2) at hw/hw.h:108
#1  put_uint16 (f=0x2427490, pv=0x1ae7580, size=2) at savevm.c:855
#2  0x000000000049c3e4 in vmstate_save_state (f=0x2427490, vmsd=0x6f0b00, opaque=0x21f5ef0) at savevm.c:1436
#3  0x000000000049c3b6 in vmstate_save_state (f=0x2427490, vmsd=0x6f0aa0, opaque=0x21f5b90) at savevm.c:1434
#4  0x000000000049c6f1 in vmstate_save (mon=<value optimized out>, f=0x2427490) at savevm.c:1459
#5  qemu_savevm_state_complete (mon=<value optimized out>, f=0x2427490) at savevm.c:1600
#6  0x000000000049455a in migrate_fd_put_ready (opaque=0x21fa8c0) at migration.c:383
#7  0x00000000004ce2eb in qemu_run_timers (clock=<value optimized out>) at qemu-timer.c:505
#8  0x00000000004ce806 in qemu_run_all_timers () at qemu-timer.c:619
#9  0x0000000000419463 in main_loop_wait (nonblocking=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:1339
#10 0x0000000000433927 in kvm_main_loop () at /build/home/tlv/akivity/qemu-kvm/qemu-kvm.c:1590
#11 0x000000000041a3a6 in main_loop (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>)
    at /build/home/tlv/akivity/qemu-kvm/vl.c:1369

#12 main (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:3257

Signature · 1 line
error compiling committee.c: too many arguments to function
#45 lore raw

Re: [Qemu-devel] [PATCH 24/26] acpi, acpi_piix: factor out GPE logic

Quoted 68 lines · Avi Kivity
Quoted 67 lines · Isaku Yamahata
Quoted 65 lines · Avi Kivity
Quoted 2 lines · Isaku Yamahata

factor out ACPI GPE logic. Later it will be used by ICH9 ACPI.

I think this patch is causing qemu-kvm failures on migration:
(gdb) bt
#0 0x000000000049aff4 in qemu_put_be16s (f=0x1a74490, pv=0x2c02580, size=2) at hw/hw.h:108
#1 put_uint16 (f=0x1a74490, pv=0x2c02580, size=2) at savevm.c:855 #2 0x000000000049c3e4 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0b00, opaque=0x1842ef0) at savevm.c:1436
#3 0x000000000049c3b6 in vmstate_save_state (f=0x1a74490, vmsd=0x6f0aa0, opaque=0x1842b90) at savevm.c:1434
#4 0x000000000049c6f1 in vmstate_save (mon=<value optimized out>, f=0x1a74490) at savevm.c:1459
#5 qemu_savevm_state_complete (mon=<value optimized out>, f=0x1a74490) at savevm.c:1600
#6 0x000000000049455a in migrate_fd_put_ready (opaque=0x1847890) at migration.c:383
#7 0x00000000004ce2eb in qemu_run_timers (clock=<value optimized out>) at qemu-timer.c:505
#8 0x00000000004ce806 in qemu_run_all_timers () at qemu-timer.c:619 #9 0x0000000000419463 in main_loop_wait (nonblocking=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:1339
#10 0x0000000000433927 in kvm_main_loop () at /build/home/tlv/akivity/qemu-kvm/qemu-kvm.c:1590
#11 0x000000000041a3a6 in main_loop (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>)

     at /build/home/tlv/akivity/qemu-kvm/vl.c:1369
 #12 main (argc=<value optimized out>, argv=<value optimized out>,
 envp=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:3257

The vmstate being migrated is "gpe".

Quoted 24 lines
 +#define VMSTATE_GPE_ARRAY(_field, _state)                            \
 + {                                                                   \
 +     .name       = (stringify(_field)),                              \
 +     .version_id = 0,                                                \
 +     .num        = GPE_LEN,                                          \
 +     .info       =&vmstate_info_uint16,                             \
 +     .size       = sizeof(uint16_t),                                 \
 +     .flags      = VMS_ARRAY | VMS_POINTER,                          \
 +     .offset     = vmstate_offset_pointer(_state, _field, uint8_t),  \
 + }
 +
   static const VMStateDescription vmstate_gpe = {
       .name = "gpe",
       .version_id = 1,
       .minimum_version_id = 1,
       .minimum_version_id_old = 1,
       .fields      = (VMStateField []) {
 -        VMSTATE_UINT16(sts, struct gpe_regs),
 -        VMSTATE_UINT16(en, struct gpe_regs),
 +        VMSTATE_GPE_ARRAY(sts, ACPIGPE),
 +        VMSTATE_GPE_ARRAY(en, ACPIGPE),
           VMSTATE_END_OF_LIST()
       }
Quoted 1 line

};

I'm no vmstate expert, but this does look odd. Why both VMS_ARRAY and VMS_POINTER? aren't we trying to save/restore a simple 16-bit value? Or at least we did before this patch.

Quoted 5 lines
Quoted 3 lines

That's right. the difference is, the new member type became uint8_t*. Does the following help?

Unforunately not. The core is very similar though:

Hmm but it seems that there is another issue.
With the previous patch, I confirmed sts and en are saved as expected.

The related VMStateDescription are defined in acpi_piix.c in the following order.
vmstate_acpi calls vmstate_gpe. and &vmstate_gpe < &vmstate_acpi.

However, your call trace shows something different.
(I'm assuming the stack trace is correct. gdb or compiler optimization?)

static const VMStateDescription vmstate_gpe = {
...

static const VMStateDescription vmstate_acpi = {
    .fields      = (VMStateField []) {

...
VMSTATE_STRUCT(gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),

Quoted 6 lines

#0 0x000000000049aff4 in qemu_put_be16s (f=0x2427490, pv=0x1ae7580, size=2) at hw/hw.h:108
#1 put_uint16 (f=0x2427490, pv=0x1ae7580, size=2) at savevm.c:855 #2 0x000000000049c3e4 in vmstate_save_state (f=0x2427490, vmsd=0x6f0b00, opaque=0x21f5ef0) at savevm.c:1436

vmsd = 0x6f0b00 = &vmstate_gpe <<<<<< correct??? opaque = 0x21f5ef0 = &PIIX4PMState->gpe

Quoted 2 lines

#3 0x000000000049c3b6 in vmstate_save_state (f=0x2427490, vmsd=0x6f0aa0, opaque=0x21f5b90) at savevm.c:1434

vmsd = 0x6f0aa0 = &vmstate_acpi <<<<<<<<<<<<< correct? opaque = 0x21f5b90 = &PIIX4PMState

opaque seems correct as
0x21f5b90 - 0x21f5ef0 = 0x348 = offsetof(PIIX4PMState, gpe)

On my environment the stack trace looks like
(gdb) where
#0 vmstate_save_state (f=0x25d16d0, vmsd=0x695940, opaque=0x283a218)

    at savevm.c:1374
#1  0x00000000004bb4f7 in vmstate_save_state (f=0x25d16d0, vmsd=0x695a40, 
    opaque=0x2839ed0) at savevm.c:1412

...

(gdb) print &vmstate_gpe
$32 = (const VMStateDescription *) 0x695940 (gdb) print &vmstate_acpi
$33 = (const VMStateDescription *) 0x695a40

thanks,

Quoted 24 lines

#4 0x000000000049c6f1 in vmstate_save (mon=<value optimized out>, f=0x2427490) at savevm.c:1459
#5 qemu_savevm_state_complete (mon=<value optimized out>, f=0x2427490) at savevm.c:1600
#6 0x000000000049455a in migrate_fd_put_ready (opaque=0x21fa8c0) at migration.c:383
#7 0x00000000004ce2eb in qemu_run_timers (clock=<value optimized out>) at qemu-timer.c:505
#8 0x00000000004ce806 in qemu_run_all_timers () at qemu-timer.c:619 #9 0x0000000000419463 in main_loop_wait (nonblocking=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:1339
#10 0x0000000000433927 in kvm_main_loop () at /build/home/tlv/akivity/qemu-kvm/qemu-kvm.c:1590
#11 0x000000000041a3a6 in main_loop (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>)

    at /build/home/tlv/akivity/qemu-kvm/vl.c:1369

#12 main (argc=<value optimized out>, argv=<value optimized out>, envp=<value optimized out>) at /build/home/tlv/akivity/qemu-kvm/vl.c:3257

Signature · 1 line
error compiling committee.c: too many arguments to function
Signature · 1 line
yamahata
#46 lore raw

Re: [Qemu-devel] [PATCH 24/26] acpi, acpi_piix: factor out GPE logic

Quoted 7 lines · Isaku Yamahata

Hmm but it seems that there is another issue.
With the previous patch, I confirmed sts and en are saved as expected.

The related VMStateDescription are defined in acpi_piix.c in the following order.
vmstate_acpi calls vmstate_gpe. and&vmstate_gpe< &vmstate_acpi.

(gdb) p &vmstate_gpe
$1 = (const VMStateDescription *) 0x6f0b00
(gdb) p &vmstate_acpi
$2 = (const VMStateDescription *) 0x6f0aa0

So no.

Quoted 13 lines

However, your call trace shows something different.
(I'm assuming the stack trace is correct. gdb or compiler optimization?)

static const VMStateDescription vmstate_gpe = {
...

static const VMStateDescription vmstate_acpi = {
     .fields      = (VMStateField []) {

...
VMSTATE_STRUCT(gpe, PIIX4PMState, 2, vmstate_gpe, ACPIGPE),

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

#0 0x000000000049aff4 in qemu_put_be16s (f=0x2427490, pv=0x1ae7580, size=2) at hw/hw.h:108
#1 put_uint16 (f=0x2427490, pv=0x1ae7580, size=2) at savevm.c:855 #2 0x000000000049c3e4 in vmstate_save_state (f=0x2427490, vmsd=0x6f0b00, opaque=0x21f5ef0) at savevm.c:1436

vmsd = 0x6f0b00 =&vmstate_gpe<<<<<< correct???

Correct.

Quoted 6 lines

opaque = 0x21f5ef0 =&PIIX4PMState->gpe

Quoted 2 lines

#3 0x000000000049c3b6 in vmstate_save_state (f=0x2427490, vmsd=0x6f0aa0, opaque=0x21f5b90) at savevm.c:1434

vmsd = 0x6f0aa0 =&vmstate_acpi<<<<<<<<<<<<< correct?

Correct.

Quoted 12 lines

opaque = 0x21f5b90 =&PIIX4PMState

opaque seems correct as
0x21f5b90 - 0x21f5ef0 = 0x348 = offsetof(PIIX4PMState, gpe)

On my environment the stack trace looks like
(gdb) where
#0 vmstate_save_state (f=0x25d16d0, vmsd=0x695940, opaque=0x283a218)

     at savevm.c:1374
#1  0x00000000004bb4f7 in vmstate_save_state (f=0x25d16d0, vmsd=0x695a40,
     opaque=0x2839ed0) at savevm.c:1412
Quoted 7 lines

...

(gdb) print&vmstate_gpe
$32 = (const VMStateDescription *) 0x695940 (gdb) print&vmstate_acpi
$33 = (const VMStateDescription *) 0x695a40

Are you using qemu-kvm.git or qemu.git? I think there are indeed two issues, your patch fixes the first and there is another that is specific to qemu-kvm.

Signature · 2 lines
I have a truly marvellous patch that fixes the bug which this
signature is too narrow to contain.
#47 lore raw

Re: [Qemu-devel] [PATCH 24/26] acpi, acpi_piix: factor out GPE logic

Quoted 3 lines · Avi Kivity

Are you using qemu-kvm.git or qemu.git? I think there are indeed two issues, your patch fixes the first and there is another that is specific to qemu-kvm.

I'm using qemu.git. I've start to have a look at qemu-kvm.git,

Signature · 1 line
yamahata
#48 lore raw

PATCH 25/26 pci_ids: add intel 82801BA pci-to-pci bridge id and PCI_CLASS_SERIAL_SMBUS

In reply to Isaku Yamahata

Adds pci id constants which will be used by q35.

---
 hw/pci_ids.h |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
hw/pci_ids.h +2 -0
index 9daea23..a597a7b 100644
@@ -30,6 +30,7 @@
 #define PCI_CLASS_SYSTEM_OTHER           0x0880
 
 #define PCI_CLASS_SERIAL_USB             0x0c03
+#define PCI_CLASS_SERIAL_SMBUS           0x0c05
 
 #define PCI_CLASS_BRIDGE_HOST            0x0600
 #define PCI_CLASS_BRIDGE_ISA             0x0601
@@ -101,6 +102,7 @@
 #define PCI_DEVICE_ID_INTEL_82441        0x1237
 #define PCI_DEVICE_ID_INTEL_82801AA_5    0x2415
 #define PCI_DEVICE_ID_INTEL_ESB_9        0x25ab
+#define PCI_DEVICE_ID_INTEL_82801BA_11   0x244e
 #define PCI_DEVICE_ID_INTEL_82371SB_0    0x7000
 #define PCI_DEVICE_ID_INTEL_82371SB_1    0x7010
 #define PCI_DEVICE_ID_INTEL_82371SB_2    0x7020
Signature · 1 line
1.7.1.1
#49 lore raw

PATCH 26/26 pc q35 based chipset emulator

In reply to Isaku Yamahata

pc q35 based chipset emulator to support pci express natively.

---
 Makefile.target |    1 +
 hw/acpi_ich9.c  |  314 ++++++++++++++++++++
 hw/acpi_ich9.h  |   53 ++++
 hw/pc_q35.c     |  359 +++++++++++++++++++++++
 hw/pci_ids.h    |   13 +
 hw/q35.c        |  877 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/q35.h        |  271 +++++++++++++++++
 hw/q35_smbus.c  |  154 ++++++++++
 8 files changed, 2042 insertions(+), 0 deletions(-)
 create mode 100644 hw/acpi_ich9.c
 create mode 100644 hw/acpi_ich9.h
 create mode 100644 hw/pc_q35.c
 create mode 100644 hw/q35.c
 create mode 100644 hw/q35.h
 create mode 100644 hw/q35_smbus.c
Makefile.target +1 -0
index d57d250..28da59f 100644
@@ -219,6 +219,7 @@ obj-i386-y += vmport.o
 obj-i386-y += device-hotplug.o pci-hotplug.o smbios.o wdt_ib700.o
 obj-i386-y += debugcon.o multiboot.o
 obj-i386-y += pc_piix.o kvmclock.o
+obj-i386-y += pc_q35.o q35.o q35_smbus.o acpi_ich9.o
 obj-i386-$(CONFIG_SPICE) += qxl.o qxl-logger.o qxl-render.o
 
 # shared objects
hw/acpi_ich9.c new file +314 -0

314 lines not on this page · raw message

hw/acpi_ich9.h new file +53 -0

53 lines not on this page · raw message

hw/pc_q35.c new file +359 -0

359 lines not on this page · raw message

hw/pci_ids.h +13 -0
index a597a7b..21cac58 100644
@@ -35,6 +35,7 @@
 #define PCI_CLASS_BRIDGE_HOST            0x0600
 #define PCI_CLASS_BRIDGE_ISA             0x0601
 #define PCI_CLASS_BRIDGE_PCI             0x0604
+#define  PCI_CLASS_BRDIGE_PCI_INF_SUB    0x01
 #define PCI_CLASS_BRIDGE_OTHER           0x0680
 
 #define PCI_CLASS_COMMUNICATION_OTHER    0x0780
@@ -111,4 +112,16 @@
 #define PCI_DEVICE_ID_INTEL_82371AB_2    0x7112
 #define PCI_DEVICE_ID_INTEL_82371AB_3    0x7113
 
+#define PCI_DEVICE_ID_INTEL_ICH9_0       0x2910
+#define PCI_DEVICE_ID_INTEL_ICH9_1       0x2917
+#define PCI_DEVICE_ID_INTEL_ICH9_2       0x2912
+#define PCI_DEVICE_ID_INTEL_ICH9_3       0x2913
+#define PCI_DEVICE_ID_INTEL_ICH9_4       0x2914
+#define PCI_DEVICE_ID_INTEL_ICH9_5       0x2919
+#define PCI_DEVICE_ID_INTEL_ICH9_6       0x2930
+#define PCI_DEVICE_ID_INTEL_ICH9_7       0x2916
+#define PCI_DEVICE_ID_INTEL_ICH9_8       0x2918
+
 #define PCI_DEVICE_ID_INTEL_ICH9_UCHI1   0x2934
+
+#define PCI_DEVICE_ID_INTEL_Q35_MCH      0x29c0
hw/q35.c new file +877 -0

877 lines not on this page · raw message

hw/q35.h new file +271 -0

271 lines not on this page · raw message

hw/q35_smbus.c new file +154 -0

154 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#50 lore raw

[Qemu-devel] ACPI table loading [was: q35 chipset support for native pci express support]

In reply to Isaku Yamahata
Quoted 10 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Example:
qemu-system-x86_64 ... -M pc_q35 -acpitable 'load_header,data=roms/seabios/src/q35-acpi-dsdt.aml

My question is unrelated to your q35 work, but I have a suggestion
here: can we avoid this "load_header" thing please? I hacked this area locally a while back while trying to run OEM-licensed windows with a SLIC table in BIOS, and wanted to come with alternative approach. Now when you reminded me that again I'd rather finish that old thing and post a real patch...

Here's my "idea". First, if there's no other options provided except of data=..., just treat it as "headerful", ie, complete with the header. Or alternatively (or at the same time), recognize "file=" the same way as "data=". We can go even further and load file/data first and patch in the other header field if specified, so it'll be possible to overwrite only certain parts of the header but load the rest of the table (complete with all other headers) from a file.

Does it make sense?

Quoted 156 lines

The motivation is to support newer hardware features because piix chipset is very old.
Especially I have PCI express in mind and this is the basic infrastructure for PCI express hot plug and PCI express native direct attach. I can boot Linux with PCIe MMCONFIG with APIC mode pci interrupt routing. I haven't tested other OSes.

The patch series consist as following

- Firstly, some PCI patches which introduce helper functions and so on.
- Then, PC initialization related patches which simplifies pc board initialization, pc_init1().
- Thirdly, factoring out the logics which are common to the existing piix and q35. ie. smram, pam and acpi logic.
- At last introduce q35 chipset emulator which is able to handle pci express natively.

Thanks,

Change from v7:
- heavily reorganized and improved.
- factoring out code duplication.
- improved irq routing fully.

Changes from split out piix specific part from pc emulator. V6
- rebased to 731c54f86988d3f28268f184fabfe9b2a32fb5d3
- PCIe MMCONFIG
- pci bridge related fixes
- chipset emulator works.
- IOAPIC patches

Changes from v5:
- rebased 0.11.0-rc0
- changed qemu_system_powerdown_register() to call qemu_system_shutdown_request() if qemu_system_shutdown() is called before registering.

Changes from v4:
- fix version number.
- rebased anthony's staging tree whose latest change set is 62969268f876c547ee64da6d60e0f363e0f1df75

Changes from v3:
- move qemu_system_powerdown() in vl.c and more generic following the comment by Marcelo Tosatti <[email protected]> acpi.c: make qemu_system_powerdown() piix independent.
- define cmos_set_s3_resume_init() and cmos_set_s3_resume() in pc.c even if TARGET_I386 isn't defined following th ecommit by Paolo Bonzini <[email protected]>
pc.c: remove a global variable, RTCState *rtc_state.
- minor compilation fixes

Changes from v2:
- clean up pc_pci_device_init() not to use unnecessary braces.

Changes from v1:
- make patches full bisectable
- typo s/allocte/allocate/
- some minor fixes
- dropped a merged patch

Isaku Yamahata (26):
pci: replace the magic, 256, for the maximum of slot
pci: add opaque argument to pci_map_irq_fn
pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt
pin swizzle
pci: add accessor function to get irq levels
piix_pci: eliminate PIIX3State::pci_irq_levels
pci_bridge: add helper function to convert PCIBridge into PCIDevice pci/p2pbr: generic pci p2p bridge
apb_pci: simplify apb_pci.c by using pci_p2pbr
dec_pci: simplify dec_pci.c by using pci_p2pbr ide/ahci/ich: use qdev.reset
ahci: add ide device initialization helper
usb/uhci: generalize initialization
usb/uhci: add ich9 usb uhci id's device
ide: consolidate drive_get(IF_IDE)
smbus_eeprom: consolidate smbus eeprom creation
pc, pc_piix: split out allocating isa irqs
pc, pc_piix: split out pc nic initialization
ioapic: move ioapic_init() from pc_piix.c to pc.c pc/piix_pci: factor out smram/pam logic
pc, i440fx: simply i440fx initialization
acpi, acpi_piix: factor out PM_TMR logic
acpi, acpi_piix: factor out PM1a EVT logic
acpi, acpi_piix: factor out PM1_CNT logic
acpi, acpi_piix: factor out GPE logic
pci_ids: add intel 82801BA pci-to-pci bridge id and
PCI_CLASS_SERIAL_SMBUS
pc q35 based chipset emulator

 Makefile.objs      |    2 +-
 Makefile.target    |    3 +-
 hw/acpi.c          |  197 ++++++++++++
 hw/acpi.h          |   68 ++++
 hw/acpi_ich9.c     |  314 +++++++++++++++++++
 hw/acpi_ich9.h     |   53 ++++
 hw/acpi_piix4.c    |  220 ++++----------
 hw/apb_pci.c       |   67 ++---
 hw/bonito.c        |    2 +-
 hw/dec_pci.c       |   51 +---
 hw/grackle_pci.c   |    2 +-
 hw/gt64xxx.c       |    2 +-
 hw/ide.h           |    6 +
 hw/ide/ahci.c      |   15 +
 hw/ide/core.c      |   14 +
 hw/ide/ich.c       |    9 +-
 hw/mips_fulong2e.c |   18 +-
 hw/mips_malta.c    |   22 +--
 hw/mips_r4k.c      |   10 +-
 hw/pam.c           |  128 ++++++++
 hw/pam.h           |   96 ++++++
 hw/pc.c            |   47 +++-
 hw/pc.h            |    7 +-
 hw/pc_piix.c       |   64 +----
 hw/pc_q35.c        |  359 +++++++++++++++++++++
 hw/pci.c           |   27 ++-
 hw/pci.h           |    6 +-
 hw/pci_bridge.c    |    6 +
 hw/pci_bridge.h    |    1 +
 hw/pci_ids.h       |   17 +
 hw/pci_internals.h |    2 +-
 hw/pci_p2pbr.c     |  151 +++++++++
 hw/pci_p2pbr.h     |   61 ++++
 hw/piix_pci.c      |  117 +++-----
 hw/ppc4xx_pci.c    |    2 +-
 hw/ppc_newworld.c  |   11 +-
 hw/ppc_oldworld.c  |   11 +-
 hw/ppc_prep.c      |   10 +-
 hw/ppce500_pci.c   |    2 +-
 hw/prep_pci.c      |    2 +-
 hw/q35.c           |  877 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/q35.h           |  271 ++++++++++++++++
 hw/q35_smbus.c     |  154 +++++++++
 hw/sh_pci.c        |    2 +-
 hw/smbus.h         |    3 +
 hw/smbus_eeprom.c  |   22 ++-
 hw/sun4u.c         |    9 +-
 hw/unin_pci.c      |    2 +-
 hw/usb-uhci.c      |   93 +++---
 hw/versatile_pci.c |    2 +-
 50 files changed, 3116 insertions(+), 521 deletions(-)
 create mode 100644 hw/acpi_ich9.c
 create mode 100644 hw/acpi_ich9.h
 create mode 100644 hw/pam.c
 create mode 100644 hw/pam.h
 create mode 100644 hw/pc_q35.c
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
 create mode 100644 hw/q35.c
 create mode 100644 hw/q35.h
 create mode 100644 hw/q35_smbus.c
#51 lore raw

Re: [Qemu-devel] ACPI table loading [was: q35 chipset support for native pci express support]

Quoted 28 lines · Michael Tokarev
Quoted 10 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Example:
qemu-system-x86_64 ... -M pc_q35 -acpitable 'load_header,data=roms/seabios/src/q35-acpi-dsdt.aml

My question is unrelated to your q35 work, but I have a suggestion
here: can we avoid this "load_header" thing please? I hacked this area locally a while back while trying to run OEM-licensed windows with a SLIC table in BIOS, and wanted to come with alternative approach. Now when you reminded me that again I'd rather finish that old thing and post a real patch...

Here's my "idea". First, if there's no other options provided except of data=..., just treat it as "headerful", ie, complete with the header. Or alternatively (or at the same time), recognize "file=" the same way as "data=". We can go even further and load file/data first and patch in the other header field if specified, so it'll be possible to overwrite only certain parts of the header but load the rest of the table (complete with all other headers) from a file.

Quoted 1 line

Does it make sense?

It sounds reasonable. As long as the patch is acceptable, I'm willing to update the patch.
Let me summarize it. Your suggestion for -acpitable is

existing behavior your suggested way
data= only
no sig=,... header is filled with zero headerful
(headerless) (new behaviour)
useless behavior

with sig=... header is created header is created
(headerless) (headerless)

thanks,

Quoted 158 lines
Quoted 156 lines

The motivation is to support newer hardware features because piix chipset is very old.
Especially I have PCI express in mind and this is the basic infrastructure for PCI express hot plug and PCI express native direct attach. I can boot Linux with PCIe MMCONFIG with APIC mode pci interrupt routing. I haven't tested other OSes.

The patch series consist as following

- Firstly, some PCI patches which introduce helper functions and so on.
- Then, PC initialization related patches which simplifies pc board initialization, pc_init1().
- Thirdly, factoring out the logics which are common to the existing piix and q35. ie. smram, pam and acpi logic.
- At last introduce q35 chipset emulator which is able to handle pci express natively.

Thanks,

Change from v7:
- heavily reorganized and improved.
- factoring out code duplication.
- improved irq routing fully.

Changes from split out piix specific part from pc emulator. V6
- rebased to 731c54f86988d3f28268f184fabfe9b2a32fb5d3
- PCIe MMCONFIG
- pci bridge related fixes
- chipset emulator works.
- IOAPIC patches

Changes from v5:
- rebased 0.11.0-rc0
- changed qemu_system_powerdown_register() to call qemu_system_shutdown_request() if qemu_system_shutdown() is called before registering.

Changes from v4:
- fix version number.
- rebased anthony's staging tree whose latest change set is 62969268f876c547ee64da6d60e0f363e0f1df75

Changes from v3:
- move qemu_system_powerdown() in vl.c and more generic following the comment by Marcelo Tosatti <[email protected]> acpi.c: make qemu_system_powerdown() piix independent.
- define cmos_set_s3_resume_init() and cmos_set_s3_resume() in pc.c even if TARGET_I386 isn't defined following th ecommit by Paolo Bonzini <[email protected]>
pc.c: remove a global variable, RTCState *rtc_state.
- minor compilation fixes

Changes from v2:
- clean up pc_pci_device_init() not to use unnecessary braces.

Changes from v1:
- make patches full bisectable
- typo s/allocte/allocate/
- some minor fixes
- dropped a merged patch

Isaku Yamahata (26):
pci: replace the magic, 256, for the maximum of slot
pci: add opaque argument to pci_map_irq_fn
pci: introduce pci_swizzle_map_irq_fn() for standardized interrupt
pin swizzle
pci: add accessor function to get irq levels
piix_pci: eliminate PIIX3State::pci_irq_levels
pci_bridge: add helper function to convert PCIBridge into PCIDevice pci/p2pbr: generic pci p2p bridge
apb_pci: simplify apb_pci.c by using pci_p2pbr
dec_pci: simplify dec_pci.c by using pci_p2pbr ide/ahci/ich: use qdev.reset
ahci: add ide device initialization helper
usb/uhci: generalize initialization
usb/uhci: add ich9 usb uhci id's device
ide: consolidate drive_get(IF_IDE)
smbus_eeprom: consolidate smbus eeprom creation
pc, pc_piix: split out allocating isa irqs
pc, pc_piix: split out pc nic initialization
ioapic: move ioapic_init() from pc_piix.c to pc.c pc/piix_pci: factor out smram/pam logic
pc, i440fx: simply i440fx initialization
acpi, acpi_piix: factor out PM_TMR logic
acpi, acpi_piix: factor out PM1a EVT logic
acpi, acpi_piix: factor out PM1_CNT logic
acpi, acpi_piix: factor out GPE logic
pci_ids: add intel 82801BA pci-to-pci bridge id and
PCI_CLASS_SERIAL_SMBUS
pc q35 based chipset emulator

 Makefile.objs      |    2 +-
 Makefile.target    |    3 +-
 hw/acpi.c          |  197 ++++++++++++
 hw/acpi.h          |   68 ++++
 hw/acpi_ich9.c     |  314 +++++++++++++++++++
 hw/acpi_ich9.h     |   53 ++++
 hw/acpi_piix4.c    |  220 ++++----------
 hw/apb_pci.c       |   67 ++---
 hw/bonito.c        |    2 +-
 hw/dec_pci.c       |   51 +---
 hw/grackle_pci.c   |    2 +-
 hw/gt64xxx.c       |    2 +-
 hw/ide.h           |    6 +
 hw/ide/ahci.c      |   15 +
 hw/ide/core.c      |   14 +
 hw/ide/ich.c       |    9 +-
 hw/mips_fulong2e.c |   18 +-
 hw/mips_malta.c    |   22 +--
 hw/mips_r4k.c      |   10 +-
 hw/pam.c           |  128 ++++++++
 hw/pam.h           |   96 ++++++
 hw/pc.c            |   47 +++-
 hw/pc.h            |    7 +-
 hw/pc_piix.c       |   64 +----
 hw/pc_q35.c        |  359 +++++++++++++++++++++
 hw/pci.c           |   27 ++-
 hw/pci.h           |    6 +-
 hw/pci_bridge.c    |    6 +
 hw/pci_bridge.h    |    1 +
 hw/pci_ids.h       |   17 +
 hw/pci_internals.h |    2 +-
 hw/pci_p2pbr.c     |  151 +++++++++
 hw/pci_p2pbr.h     |   61 ++++
 hw/piix_pci.c      |  117 +++-----
 hw/ppc4xx_pci.c    |    2 +-
 hw/ppc_newworld.c  |   11 +-
 hw/ppc_oldworld.c  |   11 +-
 hw/ppc_prep.c      |   10 +-
 hw/ppce500_pci.c   |    2 +-
 hw/prep_pci.c      |    2 +-
 hw/q35.c           |  877 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/q35.h           |  271 ++++++++++++++++
 hw/q35_smbus.c     |  154 +++++++++
 hw/sh_pci.c        |    2 +-
 hw/smbus.h         |    3 +
 hw/smbus_eeprom.c  |   22 ++-
 hw/sun4u.c         |    9 +-
 hw/unin_pci.c      |    2 +-
 hw/usb-uhci.c      |   93 +++---
 hw/versatile_pci.c |    2 +-
 50 files changed, 3116 insertions(+), 521 deletions(-)
 create mode 100644 hw/acpi_ich9.c
 create mode 100644 hw/acpi_ich9.h
 create mode 100644 hw/pam.c
 create mode 100644 hw/pam.h
 create mode 100644 hw/pc_q35.c
 create mode 100644 hw/pci_p2pbr.c
 create mode 100644 hw/pci_p2pbr.h
 create mode 100644 hw/q35.c
 create mode 100644 hw/q35.h
 create mode 100644 hw/q35_smbus.c
Signature · 1 line
yamahata
#52 lore raw

[Qemu-devel] RFC: ACPI table loading

Quoted 28 lines · Isaku Yamahata
Quoted 21 lines · Michael Tokarev
Quoted 2 lines · Isaku Yamahata

Example:
qemu-system-x86_64 ... -M pc_q35 -acpitable 'load_header,data=roms/seabios/src/q35-acpi-dsdt.aml

My question is unrelated to your q35 work, but I have a suggestion
here: can we avoid this "load_header" thing please? I hacked this area locally a while back while trying to run OEM-licensed windows with a SLIC table in BIOS, and wanted to come with alternative approach. Now when you reminded me that again I'd rather finish that old thing and post a real patch...

Here's my "idea". First, if there's no other options provided except of data=..., just treat it as "headerful", ie, complete with the header. Or alternatively (or at the same time), recognize "file=" the same way as "data=". We can go even further and load file/data first and patch in the other header field if specified, so it'll be possible to overwrite only certain parts of the header but load the rest of the table (complete with all other headers) from a file.

Quoted 1 line

Does it make sense?

It sounds reasonable. As long as the patch is acceptable, I'm willing to update the patch.
Let me summarize it. Your suggestion for -acpitable is

Quoted 8 lines

existing behavior your suggested way
data= only
no sig=,... header is filled with zero headerful
(headerless) (new behaviour)
useless behavior

with sig=... header is created header is created
(headerless) (headerless)

I just implemented the whole thing, and refined it at the same time. With data= it works the same way as before, so no new behavour is introduced. Only with file= it is possible to specify whole table (with header) in a file, but other header fields specified on the command line (sig= etc) will work still, replacing the corresponding fields in the header read from the file.

Something like the below, it's just an RFC, but it appears to work.

/mjt

Subject: rewamp acpitable parsing, and allow specifying complete file with headers

This patch almost rewrites acpi_table_add() function (but still leaves it using old get_param_value() interface). The result is that it's now possible to specify whole table (together with a header) in an external file, instead of just data portion, with a new file= parameter, but at the same time it's still possible to specify header fields as before.

hw/acpi.c +190 -133
index 237526d..d12527e 100644
@@ -22,18 +22,8 @@
 #include "qemu-kvm.h"
 #include "string.h"
 
-struct acpi_table_header
-{
-    char signature [4];    /* ACPI signature (4 ASCII characters) */
-    uint32_t length;          /* Length of table, in bytes, including header */
-    uint8_t revision;         /* ACPI Specification minor version # */
-    uint8_t checksum;         /* To make sum of entire table == 0 */
-    char oem_id [6];       /* OEM identification */
-    char oem_table_id [8]; /* OEM table identification */
-    uint32_t oem_revision;    /* OEM revision number */
-    char asl_compiler_id [4]; /* ASL compiler vendor ID */
-    uint32_t asl_compiler_revision; /* ASL compiler revision number */
-} __attribute__((packed));
+
+#define ACPI_TABLE_HDR_SIZE (4+4+1+1+6+8+4+4+4)
 
 char *acpi_tables;
 size_t acpi_tables_len;
@@ -50,153 +40,220 @@ static int acpi_checksum(const uint8_t *data, int len)
 int acpi_table_add(const char *t)
 {
     static const char *dfl_id = "QEMUQEMU";
-    char buf[1024], *p, *f;
-    struct acpi_table_header acpi_hdr;
+    char buf[1024], *f, *p;
     unsigned long val;
-    uint32_t length;
-    struct acpi_table_header *acpi_hdr_p;
-    size_t off;
-
-    memset(&acpi_hdr, 0, sizeof(acpi_hdr));
-
-    if (get_param_value(buf, sizeof(buf), "sig", t)) {
-        strncpy(acpi_hdr.signature, buf, 4);
-    } else {
-        strncpy(acpi_hdr.signature, dfl_id, 4);
-    }
-    if (get_param_value(buf, sizeof(buf), "rev", t)) {
+    size_t len, start;
+    bool has_header;
+    int changed;
+
+    /*XXX fixme: this function uses obsolete argument parsing interface */
+    /*XXX note: all 32bit accesses in there are misaligned */
+
+    if (get_param_value(buf, sizeof(buf), "data", t))
+    {
+	has_header = 0;
+    }
+    else if (get_param_value(buf, sizeof(buf), "file", t))
+    {
+	has_header = 1;
+    }
+    else {
+	has_header = 0;
+	buf[0] = '\0';
+    }
+
+    if (!acpi_tables)
+    {
+	acpi_tables_len = sizeof(uint16_t);
+	acpi_tables = qemu_mallocz(acpi_tables_len);
+    }
+    start = acpi_tables_len;
+
+    len = sizeof(uint16_t) + ACPI_TABLE_HDR_SIZE;
+    acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len + len);
+    acpi_tables_len += sizeof(uint16_t);
+
+    if (!has_header)
+    {
+       memset(acpi_tables + acpi_tables_len, 0, ACPI_TABLE_HDR_SIZE);
+       acpi_tables_len += ACPI_TABLE_HDR_SIZE;
+    }
+
+    /* now read in the data files, reallocating buffer as needed */
+
+    for(f = strtok(buf, ":"); f; f = strtok(NULL, ":"))
+    {
+	int fd = open(f, O_RDONLY);
+
+        if(fd < 0)
+	{
+	    /*XXX fixme: report error */
+            goto out;
+	}
+
+	for(;;)
+        {
+            char data[8192];
+	    int r = read(fd, data, sizeof(data));
+	    if (r == 0)
+	    {
+	      break;
+	    }
+	    else if (r > 0)
+	    {
+		acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len + r);
+		memcpy(acpi_tables + acpi_tables_len, data, r);
+		acpi_tables_len += r;
+	    }
+	    else if (errno != EINTR)
+	    {
+		/*XXX fixme: report error */
+		close(fd);
+		goto out;
+	    }
+	}
+
+	close(fd);
+    }
+
+    /* fill in the complete length of the table */
+    len = acpi_tables_len - start - sizeof(uint16_t);
+    f = acpi_tables + start;
+    *(uint16_t*)f = cpu_to_le32(len);
+    f += sizeof(uint16_t);
+
+    /* now fill in the header fields */
+    changed = 0;
+
+    /* 0..3, signature, string (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "sig", t))
+    {
+        strncpy(f + 0, buf, 4);
+	++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 0, dfl_id, 4);
+    }
+
+    /* 4..7, length of the table, in bytes, including header (4 bytes) */
+
+    /* 8, ACPI specification minor version #, 1 byte */
+    if (get_param_value(buf, sizeof(buf), "rev", t))
+    {
         val = strtoul(buf, &p, 10);
         if (val > 255 || *p != '\0')
-            goto out;
-    } else {
-        val = 1;
+            goto out;	/*XXX fixme: report error */
+	f[8] = (uint8_t)val;
+	++changed;
+    }
+    else if (!has_header)
+    {
+	f[8] = 1;
     }
-    acpi_hdr.revision = (int8_t)val;
 
-    if (get_param_value(buf, sizeof(buf), "oem_id", t)) {
-        strncpy(acpi_hdr.oem_id, buf, 6);
-    } else {
-        strncpy(acpi_hdr.oem_id, dfl_id, 6);
+    /* 9, checksum of entire table (1 byte) */
+
+    /* 10..15 OEM identification (6 bytes) */
+    if (get_param_value(buf, sizeof(buf), "oem_id", t))
+    {
+        strncpy(f + 10, buf, 6);
+	++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 10, dfl_id, 6);
     }
 
-    if (get_param_value(buf, sizeof(buf), "oem_table_id", t)) {
-        strncpy(acpi_hdr.oem_table_id, buf, 8);
-    } else {
-        strncpy(acpi_hdr.oem_table_id, dfl_id, 8);
+    /* 16..23 OEM table identifiaction, 8 bytes */
+    if (get_param_value(buf, sizeof(buf), "oem_table_id", t))
+    {
+        strncpy(f + 16, buf, 8);
+	++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 16, dfl_id, 8);
     }
 
-    if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {
+    /* 24..27 OEM revision number, 4 bytes */
+    if (get_param_value(buf, sizeof(buf), "oem_rev", t))
+    {
         val = strtol(buf, &p, 10);
         if(*p != '\0')
-            goto out;
-    } else {
-        val = 1;
+            goto out;	/*XXX fixme: report error */
+	*(uint32_t*)(f + 24) = cpu_to_le32(val);
+	++changed;
+    } else if (!has_header)
+    {
+	*(uint32_t*)(f + 24) = cpu_to_le32(1);
     }
-    acpi_hdr.oem_revision = cpu_to_le32(val);
 
-    if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t)) {
-        strncpy(acpi_hdr.asl_compiler_id, buf, 4);
-    } else {
-        strncpy(acpi_hdr.asl_compiler_id, dfl_id, 4);
+    /* 28..31 ASL compiler vendor ID (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t))
+    {
+        strncpy(f + 28, buf, 4);
+        ++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 28, dfl_id, 4);
     }
 
-    if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {
+    /* 32..35 ASL compiler revision number (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t))
+    {
         val = strtol(buf, &p, 10);
         if(*p != '\0')
-            goto out;
-    } else {
-        val = 1;
+            goto out;	/*XXX fixme: report error */
+	*(uint32_t*)(f + 32) = cpu_to_le32(val);
+	++changed;
     }
-    acpi_hdr.asl_compiler_revision = cpu_to_le32(val);
-
-    if (!get_param_value(buf, sizeof(buf), "data", t)) {
-         buf[0] = '\0';
+    else if (!has_header) {
+	*(uint32_t*)(f + 32) = cpu_to_le32(1);
     }
 
-    length = sizeof(acpi_hdr);
+    /* 4..7 length of the table including header, in bytes (4 bytes) */
+    if (!has_header)
+    {
+	if (!changed)
+	    fprintf(stderr,
+		"warning: acpi table specified with data="
+		" but no table headers are provided, defaults are used\n");
+    }
+    else
+    {
+	/* check if actual length is correct */
+	val = le32_to_cpu(*(uint32_t*)(f + 4));
+	if (val != len)
+	{
+	    fprintf(stderr,
+		"warning: acpi table specified with file= has wrong length,"
+		" header says %lu, actual size %u\n",
+		val, len);
+	    ++changed;
+	}
+    }
 
-    f = buf;
-    while (buf[0]) {
-        struct stat s;
-        char *n = strchr(f, ':');
-        if (n)
-            *n = '\0';
-        if(stat(f, &s) < 0) {
-            fprintf(stderr, "Can't stat file '%s': %s\n", f, strerror(errno));
-            goto out;
-        }
-        length += s.st_size;
-        if (!n)
-            break;
-        *n = ':';
-        f = n + 1;
-    }
-
-    if (!acpi_tables) {
-        acpi_tables_len = sizeof(uint16_t);
-        acpi_tables = qemu_mallocz(acpi_tables_len);
-    }
-    acpi_tables = qemu_realloc(acpi_tables,
-                               acpi_tables_len + sizeof(uint16_t) + length);
-    p = acpi_tables + acpi_tables_len;
-    acpi_tables_len += sizeof(uint16_t) + length;
-
-    *(uint16_t*)p = cpu_to_le32(length);
-    p += sizeof(uint16_t);
-    memcpy(p, &acpi_hdr, sizeof(acpi_hdr));
-    off = sizeof(acpi_hdr);
-
-    f = buf;
-    while (buf[0]) {
-        struct stat s;
-        int fd;
-        char *n = strchr(f, ':');
-        if (n)
-            *n = '\0';
-        fd = open(f, O_RDONLY);
+    /* fix table length */
+    /* we may avoid putting length here if has_header is true */
+    *(uint32_t*)(f + 4) = cpu_to_le32(len);
+
+    /* 9 checksum (1 byte) */
+    /* we may as well leave checksum intact if has_header is true */
+    /* alternatively there may be a way to set cksum to a given value */
+    if (changed || !has_header || 1)
+    {
+	f[9] = 0;
+	f[9] = acpi_checksum((uint8_t*)f, len);
+    }
 
-        if(fd < 0)
-            goto out;
-        if(fstat(fd, &s) < 0) {
-            close(fd);
-            goto out;
-        }
-
-        /* off < length is necessary because file size can be changed
-           under our foot */
-        while(s.st_size && off < length) {
-            int r;
-            r = read(fd, p + off, s.st_size);
-            if (r > 0) {
-                off += r;
-                s.st_size -= r;
-            } else if ((r < 0 && errno != EINTR) || r == 0) {
-                close(fd);
-                goto out;
-            }
-        }
-
-        close(fd);
-        if (!n)
-            break;
-        f = n + 1;
-    }
-    if (off < length) {
-        /* don't pass random value in process to guest */
-        memset(p + off, 0, length - off);
-    }
-
-    acpi_hdr_p = (struct acpi_table_header*)p;
-    acpi_hdr_p->length = cpu_to_le32(length);
-    acpi_hdr_p->checksum = acpi_checksum((uint8_t*)p, length);
     /* increase number of tables */
     (*(uint16_t*)acpi_tables) =
 	    cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1);
     return 0;
+
 out:
-    if (acpi_tables) {
-        qemu_free(acpi_tables);
-        acpi_tables = NULL;
-    }
+    acpi_tables_len = start;
     return -1;
 }
qemu-options.hx +6 -1
index 18f54d2..e1d26b4 100644
@@ -995,12 +995,17 @@ Enable virtio balloon device (default), optionally with PCI address
 ETEXI
 
 DEF("acpitable", HAS_ARG, QEMU_OPTION_acpitable,
-    "-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,data=file1[:file2]...]\n"
+    "-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,{data|file}=file1[:file2]...]\n"
     "                ACPI table description\n", QEMU_ARCH_I386)
 STEXI
 @item -acpitable [sig=@var{str}][,rev=@var{n}][,oem_id=@var{str}][,oem_table_id=@var{str}][,oem_rev=@var{n}] [,asl_compiler_id=@var{str}][,asl_compiler_rev=@var{n}][,data=@var{file1}[:@var{file2}]...]
 @findex -acpitable
 Add ACPI table with specified header fields and context from specified files.
+For file=, take whole ACPI table from the specified files, including all
+ACPI headers (possible overridden by other options).
+For data=, only data
+portion of the table is used, all header information is specified in the
+command line.
 ETEXI
 
 DEF("smbios", HAS_ARG, QEMU_OPTION_smbios,
#53 lore raw

Re: [Qemu-devel] RFC: ACPI table loading

The behavior seems reasonable. So I cleaned it up for upstream merge.

thanks,

Quoted 1 line

From cd336e50ebda63ecd84f8172dcf4d4456059d615 Mon Sep 17 00:00:00 2001

Message-Id: <cd336e50ebda63ecd84f8172dcf4d4456059d615.1300332741.git.yamahata@valinux.co.jp>
From: Isaku Yamahata <[email protected]>
Date: Thu, 17 Mar 2011 12:28:52 +0900
Subject: [PATCH] acpi: rewamp acpitable parsing, and allow specifying complete file with headers

This patch almost rewrites acpi_table_add() function (but still leaves it using old get_param_value() interface). The result is that it's now possible to specify whole table (together with a header) in an external file, instead of just data portion, with a new file= parameter, but at the same time it's still possible to specify header fields as before.

---
Changes v2:
- rebased to 31d3c9b8c15d7b42f508d5fc2adc4abb7c732b70
- style fix
- eliminated unaligned access
- replace magic numbers with symbolic constants
- error report

---
 hw/acpi.c |  294 ++++++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 184 insertions(+), 110 deletions(-)
hw/acpi.c +184 -110
index 8071e7b..b058e20 100644
@@ -32,6 +32,30 @@ struct acpi_table_header
     uint32_t asl_compiler_revision; /* ASL compiler revision number */
 } __attribute__((packed));
 
+#define ACPI_TABLE_OFF(x)       (offsetof(struct acpi_table_header, x))
+#define ACPI_TABLE_SIZE(x)      (sizeof(((struct acpi_table_header*)0)->x))
+
+#define ACPI_TABLE_SIG_OFF              ACPI_TABLE_OFF(signature)
+#define ACPI_TABLE_SIG_SIZE             ACPI_TABLE_SIZE(signature)
+#define ACPI_TABLE_LEN_OFF              ACPI_TABLE_OFF(length)
+#define ACPI_TABLE_LEN_SIZE             ACPI_TABLE_SIZE(length)
+#define ACPI_TABLE_REV_OFF              ACPI_TABLE_OFF(revision)
+#define ACPI_TABLE_REV_SIZE             ACPI_TABLE_SIZE(revision)
+#define ACPI_TABLE_CSUM_OFF             ACPI_TABLE_OFF(checksum)
+#define ACPI_TABLE_CSUM_SIZE            ACPI_TABLE_SIZE(checksum)
+#define ACPI_TABLE_OEM_ID_OFF           ACPI_TABLE_OFF(oem_id)
+#define ACPI_TABLE_OEM_ID_SIZE          ACPI_TABLE_SIZE(oem_id)
+#define ACPI_TABLE_OEM_TABLE_ID_OFF     ACPI_TABLE_OFF(oem_table_id)
+#define ACPI_TABLE_OEM_TABLE_ID_SIZE    ACPI_TABLE_SIZE(oem_table_id)
+#define ACPI_TABLE_OEM_REV_OFF          ACPI_TABLE_OFF(oem_revision)
+#define ACPI_TABLE_OEM_REV_SIZE         ACPI_TABLE_SIZE(oem_revision)
+#define ACPI_TABLE_ASL_COMPILER_ID_OFF  ACPI_TABLE_OFF(asl_compiler_id)
+#define ACPI_TABLE_ASL_COMPILER_ID_SIZE ACPI_TABLE_SIZE(asl_compiler_id)
+#define ACPI_TABLE_ASL_COMPILER_REV_OFF ACPI_TABLE_OFF(asl_compiler_revision)
+#define ACPI_TABLE_ASL_COMPILER_REV_SIZE ACPI_TABLE_SIZE(asl_compiler_revision)
+
+#define ACPI_TABLE_HDR_SIZE sizeof(struct acpi_table_header)
+
 char *acpi_tables;
 size_t acpi_tables_len;
 
@@ -44,156 +68,206 @@ static int acpi_checksum(const uint8_t *data, int len)
     return (-sum) & 0xff;
 }
 
+/* XXX fixme: this function uses obsolete argument parsing interface */
 int acpi_table_add(const char *t)
 {
     static const char *dfl_id = "QEMUQEMU";
-    char buf[1024], *p, *f;
-    struct acpi_table_header acpi_hdr;
+    char buf[1024], *f, *p;
     unsigned long val;
-    uint32_t length;
-    struct acpi_table_header *acpi_hdr_p;
-    size_t off;
+    uint16_t val16;
+    uint32_t val32;
+    size_t len, start;
+    bool has_header;
+    int changed;
 
-    memset(&acpi_hdr, 0, sizeof(acpi_hdr));
-  
-    if (get_param_value(buf, sizeof(buf), "sig", t)) {
-        strncpy(acpi_hdr.signature, buf, 4);
+    if (get_param_value(buf, sizeof(buf), "data", t)) {
+        has_header = false;
+    } else if (get_param_value(buf, sizeof(buf), "file", t)) {
+        has_header = true;
     } else {
-        strncpy(acpi_hdr.signature, dfl_id, 4);
+        has_header = 0;
+        buf[0] = '\0';
+    }
+
+    if (!acpi_tables) {
+        acpi_tables_len = sizeof(uint16_t);
+        acpi_tables = qemu_mallocz(acpi_tables_len);
+    }
+    start = acpi_tables_len;
+
+    len = sizeof(uint16_t) + ACPI_TABLE_HDR_SIZE;
+    acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len + len);
+    acpi_tables_len += sizeof(uint16_t);
+
+    if (!has_header) {
+        memset(acpi_tables + acpi_tables_len, 0, ACPI_TABLE_HDR_SIZE);
+        acpi_tables_len += ACPI_TABLE_HDR_SIZE;
     }
+
+    /* now read in the data files, reallocating buffer as needed */
+    for(f = strtok(buf, ":"); f; f = strtok(NULL, ":")) {
+        int fd = open(f, O_RDONLY);
+        if(fd < 0) {
+            fprintf(stderr, "can't open file %s: %s\n", f, strerror(errno));
+            goto out;
+        }
+
+        for(;;) {
+            char data[8192];
+            ssize_t r = read(fd, data, sizeof(data));
+            if (r == 0) {
+                break;
+            } else if (r > 0) {
+                acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len + r);
+                memcpy(acpi_tables + acpi_tables_len, data, r);
+                acpi_tables_len += r;
+            } else if (errno != EINTR) {
+                fprintf(stderr, "can't read file %s: %s\n",
+                        f, strerror(errno));
+                close(fd);
+                goto out;
+            }
+        }
+
+        close(fd);
+    }
+
+    /* fill in the complete length of the table */
+    len = acpi_tables_len - start - sizeof(uint16_t);
+    f = acpi_tables + start;
+    val16 = cpu_to_le16(len);
+    memcpy(f, &val16, sizeof(uint16_t));
+    f += sizeof(uint16_t);
+
+    /* now fill in the header fields */
+    changed = 0;
+
+    /* 0..3, signature, string (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "sig", t)) {
+        strncpy(f + ACPI_TABLE_SIG_OFF, buf, ACPI_TABLE_SIG_SIZE);
+        ++changed;
+    } else if (!has_header) {
+        strncpy(f + ACPI_TABLE_SIG_OFF, dfl_id, ACPI_TABLE_SIG_SIZE);
+    }
+
+    /* 4..7, length of the table, in bytes, including header (4 bytes) */
+
+    /* 8, ACPI specification minor version #, 1 byte */
     if (get_param_value(buf, sizeof(buf), "rev", t)) {
         val = strtoul(buf, &p, 10);
-        if (val > 255 || *p != '\0')
+        if (val > 255 || *p != '\0') {
+            fprintf(stderr, "invalid acpi rev.\n");
             goto out;
-    } else {
-        val = 1;
+        }
+        f[ACPI_TABLE_REV_OFF] = (uint8_t)val;
+        ++changed;
+    } else if (!has_header) {
+        f[ACPI_TABLE_REV_OFF] = 1;
     }
-    acpi_hdr.revision = (int8_t)val;
 
+    /* 9, checksum of entire table (1 byte)
+       this will be processed after all the headers are modified */
+
+    /* 10..15 OEM identification (6 bytes) */
     if (get_param_value(buf, sizeof(buf), "oem_id", t)) {
-        strncpy(acpi_hdr.oem_id, buf, 6);
-    } else {
-        strncpy(acpi_hdr.oem_id, dfl_id, 6);
+        strncpy(f + ACPI_TABLE_OEM_ID_OFF, buf, ACPI_TABLE_OEM_ID_SIZE);
+        ++changed;
+    } else if (!has_header) {
+        strncpy(f + ACPI_TABLE_OEM_ID_OFF, dfl_id, ACPI_TABLE_OEM_ID_SIZE);
     }
 
+    /* 16..23 OEM table identifiaction, 8 bytes */
     if (get_param_value(buf, sizeof(buf), "oem_table_id", t)) {
-        strncpy(acpi_hdr.oem_table_id, buf, 8);
-    } else {
-        strncpy(acpi_hdr.oem_table_id, dfl_id, 8);
+        strncpy(f + ACPI_TABLE_OEM_TABLE_ID_OFF, buf,
+                ACPI_TABLE_OEM_TABLE_ID_SIZE);
+        ++changed;
+    } else if (!has_header) {
+        strncpy(f + ACPI_TABLE_OEM_TABLE_ID_OFF, dfl_id,
+                ACPI_TABLE_OEM_TABLE_ID_SIZE);
     }
 
+    /* 24..27 OEM revision number, 4 bytes */
     if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {
         val = strtol(buf, &p, 10);
-        if(*p != '\0')
+        if(*p != '\0') {
+            fprintf(stderr, "invalid acpi oem_rev.\n");
             goto out;
-    } else {
-        val = 1;
+        }
+        val32 = cpu_to_le32(val);
+        memcpy(f + ACPI_TABLE_OEM_REV_OFF, &val32, ACPI_TABLE_OEM_REV_SIZE);
+        ++changed;
+    } else if (!has_header) {
+        val32 = cpu_to_le32(1);
+        memcpy(f + ACPI_TABLE_OEM_REV_OFF, &val32, ACPI_TABLE_OEM_REV_SIZE);
     }
-    acpi_hdr.oem_revision = cpu_to_le32(val);
 
+    /* 28..31 ASL compiler vendor ID (4 bytes) */
     if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t)) {
-        strncpy(acpi_hdr.asl_compiler_id, buf, 4);
-    } else {
-        strncpy(acpi_hdr.asl_compiler_id, dfl_id, 4);
+        strncpy(f + ACPI_TABLE_ASL_COMPILER_ID_OFF, buf,
+                ACPI_TABLE_ASL_COMPILER_ID_SIZE);
+        ++changed;
+    } else if (!has_header) {
+        strncpy(f + ACPI_TABLE_ASL_COMPILER_ID_OFF, dfl_id,
+                ACPI_TABLE_ASL_COMPILER_ID_SIZE);
     }
 
+    /* 32..35 ASL compiler revision number (4 bytes) */
     if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {
         val = strtol(buf, &p, 10);
-        if(*p != '\0')
-            goto out;
-    } else {
-        val = 1;
-    }
-    acpi_hdr.asl_compiler_revision = cpu_to_le32(val);
-    
-    if (!get_param_value(buf, sizeof(buf), "data", t)) {
-         buf[0] = '\0';
-    }
-
-    length = sizeof(acpi_hdr);
-
-    f = buf;
-    while (buf[0]) {
-        struct stat s;
-        char *n = strchr(f, ':');
-        if (n)
-            *n = '\0';
-        if(stat(f, &s) < 0) {
-            fprintf(stderr, "Can't stat file '%s': %s\n", f, strerror(errno));
+        if(*p != '\0') {
+            fprintf(stderr, "invalid acpi asl_compiler_rev.\n");
             goto out;
         }
-        length += s.st_size;
-        if (!n)
-            break;
-        *n = ':';
-        f = n + 1;
-    }
+        val32 = cpu_to_le32(val);
+        memcpy(f + ACPI_TABLE_ASL_COMPILER_REV_OFF, &val32,
+               ACPI_TABLE_ASL_COMPILER_REV_SIZE);
+        ++changed;
+    } else if (!has_header) {
+        val32 = cpu_to_le32(1);
+        memcpy(f + ACPI_TABLE_ASL_COMPILER_REV_OFF, &val32,
+               ACPI_TABLE_ASL_COMPILER_REV_SIZE);
 
-    if (!acpi_tables) {
-        acpi_tables_len = sizeof(uint16_t);
-        acpi_tables = qemu_mallocz(acpi_tables_len);
     }
-    acpi_tables = qemu_realloc(acpi_tables,
-                               acpi_tables_len + sizeof(uint16_t) + length);
-    p = acpi_tables + acpi_tables_len;
-    acpi_tables_len += sizeof(uint16_t) + length;
-
-    *(uint16_t*)p = cpu_to_le32(length);
-    p += sizeof(uint16_t);
-    memcpy(p, &acpi_hdr, sizeof(acpi_hdr));
-    off = sizeof(acpi_hdr);
-
-    f = buf;
-    while (buf[0]) {
-        struct stat s;
-        int fd;
-        char *n = strchr(f, ':');
-        if (n)
-            *n = '\0';
-        fd = open(f, O_RDONLY);
-
-        if(fd < 0)
-            goto out;
-        if(fstat(fd, &s) < 0) {
-            close(fd);
-            goto out;
-        }
 
-        /* off < length is necessary because file size can be changed
-           under our foot */
-        while(s.st_size && off < length) {
-            int r;
-            r = read(fd, p + off, s.st_size);
-            if (r > 0) {
-                off += r;
-                s.st_size -= r;
-            } else if ((r < 0 && errno != EINTR) || r == 0) {
-                close(fd);
-                goto out;
-            }
+    /* 4..7 length of the table including header, in bytes (4 bytes) */
+    if (!has_header) {
+        if (!changed) {
+            fprintf(stderr,
+                    "warning: acpi table specified with data="
+                    " but no table headers are provided, defaults are used\n");
+        }
+    } else {
+        /* check if actual length is correct */
+        memcpy(&val32, f + ACPI_TABLE_LEN_OFF, ACPI_TABLE_LEN_SIZE);
+        val = le32_to_cpu(val32);
+        if (val != len) {
+            fprintf(stderr,
+                    "warning: acpi table specified with file= has wrong length,"
+                    " header says %lu, actual size %zu\n",
+                    val, len);
+            ++changed;
         }
-
-        close(fd);
-        if (!n)
-            break;
-        f = n + 1;
     }
-    if (off < length) {
-        /* don't pass random value in process to guest */
-        memset(p + off, 0, length - off);
+
+    /* fix table length */
+    /* we may avoid putting length here if has_header is true */
+    val32 = cpu_to_le32(len);
+    memcpy(f + ACPI_TABLE_LEN_OFF, &val32, ACPI_TABLE_LEN_SIZE);
+
+    /* 9 checksum (1 byte) */
+    /* we may as well leave checksum intact if has_header is true */
+    /* alternatively there may be a way to set cksum to a given value */
+    if (changed || !has_header || 1) {
+        f[ACPI_TABLE_CSUM_OFF] = 0;
+        f[ACPI_TABLE_CSUM_OFF] = acpi_checksum((uint8_t*)f, len);
     }
 
-    acpi_hdr_p = (struct acpi_table_header*)p;
-    acpi_hdr_p->length = cpu_to_le32(length);
-    acpi_hdr_p->checksum = acpi_checksum((uint8_t*)p, length);
     /* increase number of tables */
     (*(uint16_t*)acpi_tables) =
-	    cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1);
+        cpu_to_le16(le16_to_cpu(*(uint16_t*)acpi_tables) + 1);
     return 0;
+
 out:
-    if (acpi_tables) {
-        qemu_free(acpi_tables);
-        acpi_tables = NULL;
-    }
+    acpi_tables_len = start;
     return -1;
 }
Signature · 1 line
1.7.1.1
Quoted 453 lines · Michael Tokarev
Quoted 28 lines · Isaku Yamahata
Quoted 21 lines · Michael Tokarev
Quoted 2 lines · Isaku Yamahata

Example:
qemu-system-x86_64 ... -M pc_q35 -acpitable 'load_header,data=roms/seabios/src/q35-acpi-dsdt.aml

My question is unrelated to your q35 work, but I have a suggestion
here: can we avoid this "load_header" thing please? I hacked this area locally a while back while trying to run OEM-licensed windows with a SLIC table in BIOS, and wanted to come with alternative approach. Now when you reminded me that again I'd rather finish that old thing and post a real patch...

Here's my "idea". First, if there's no other options provided except of data=..., just treat it as "headerful", ie, complete with the header. Or alternatively (or at the same time), recognize "file=" the same way as "data=". We can go even further and load file/data first and patch in the other header field if specified, so it'll be possible to overwrite only certain parts of the header but load the rest of the table (complete with all other headers) from a file.

Quoted 1 line

Does it make sense?

It sounds reasonable. As long as the patch is acceptable, I'm willing to update the patch.
Let me summarize it. Your suggestion for -acpitable is

Quoted 8 lines

existing behavior your suggested way
data= only
no sig=,... header is filled with zero headerful
(headerless) (new behaviour)
useless behavior

with sig=... header is created header is created
(headerless) (headerless)

I just implemented the whole thing, and refined it at the same time. With data= it works the same way as before, so no new behavour is introduced. Only with file= it is possible to specify whole table (with header) in a file, but other header fields specified on the command line (sig= etc) will work still, replacing the corresponding fields in the header read from the file.

Something like the below, it's just an RFC, but it appears to work.

/mjt

Subject: rewamp acpitable parsing, and allow specifying complete file with headers

This patch almost rewrites acpi_table_add() function (but still leaves it using old get_param_value() interface). The result is that it's now possible to specify whole table (together with a header) in an external file, instead of just data portion, with a new file= parameter, but at the same time it's still possible to specify header fields as before.

hw/acpi.c +190 -133
index 237526d..d12527e 100644
@@ -22,18 +22,8 @@
 #include "qemu-kvm.h"
 #include "string.h"
 
-struct acpi_table_header
-{
-    char signature [4];    /* ACPI signature (4 ASCII characters) */
-    uint32_t length;          /* Length of table, in bytes, including header */
-    uint8_t revision;         /* ACPI Specification minor version # */
-    uint8_t checksum;         /* To make sum of entire table == 0 */
-    char oem_id [6];       /* OEM identification */
-    char oem_table_id [8]; /* OEM table identification */
-    uint32_t oem_revision;    /* OEM revision number */
-    char asl_compiler_id [4]; /* ASL compiler vendor ID */
-    uint32_t asl_compiler_revision; /* ASL compiler revision number */
-} __attribute__((packed));
+
+#define ACPI_TABLE_HDR_SIZE (4+4+1+1+6+8+4+4+4)
 
 char *acpi_tables;
 size_t acpi_tables_len;
@@ -50,153 +40,220 @@ static int acpi_checksum(const uint8_t *data, int len)
 int acpi_table_add(const char *t)
 {
     static const char *dfl_id = "QEMUQEMU";
-    char buf[1024], *p, *f;
-    struct acpi_table_header acpi_hdr;
+    char buf[1024], *f, *p;
     unsigned long val;
-    uint32_t length;
-    struct acpi_table_header *acpi_hdr_p;
-    size_t off;
-
-    memset(&acpi_hdr, 0, sizeof(acpi_hdr));
-
-    if (get_param_value(buf, sizeof(buf), "sig", t)) {
-        strncpy(acpi_hdr.signature, buf, 4);
-    } else {
-        strncpy(acpi_hdr.signature, dfl_id, 4);
-    }
-    if (get_param_value(buf, sizeof(buf), "rev", t)) {
+    size_t len, start;
+    bool has_header;
+    int changed;
+
+    /*XXX fixme: this function uses obsolete argument parsing interface */
+    /*XXX note: all 32bit accesses in there are misaligned */
+
+    if (get_param_value(buf, sizeof(buf), "data", t))
+    {
+	has_header = 0;
+    }
+    else if (get_param_value(buf, sizeof(buf), "file", t))
+    {
+	has_header = 1;
+    }
+    else {
+	has_header = 0;
+	buf[0] = '\0';
+    }
+
+    if (!acpi_tables)
+    {
+	acpi_tables_len = sizeof(uint16_t);
+	acpi_tables = qemu_mallocz(acpi_tables_len);
+    }
+    start = acpi_tables_len;
+
+    len = sizeof(uint16_t) + ACPI_TABLE_HDR_SIZE;
+    acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len + len);
+    acpi_tables_len += sizeof(uint16_t);
+
+    if (!has_header)
+    {
+       memset(acpi_tables + acpi_tables_len, 0, ACPI_TABLE_HDR_SIZE);
+       acpi_tables_len += ACPI_TABLE_HDR_SIZE;
+    }
+
+    /* now read in the data files, reallocating buffer as needed */
+
+    for(f = strtok(buf, ":"); f; f = strtok(NULL, ":"))
+    {
+	int fd = open(f, O_RDONLY);
+
+        if(fd < 0)
+	{
+	    /*XXX fixme: report error */
+            goto out;
+	}
+
+	for(;;)
+        {
+            char data[8192];
+	    int r = read(fd, data, sizeof(data));
+	    if (r == 0)
+	    {
+	      break;
+	    }
+	    else if (r > 0)
+	    {
+		acpi_tables = qemu_realloc(acpi_tables, acpi_tables_len + r);
+		memcpy(acpi_tables + acpi_tables_len, data, r);
+		acpi_tables_len += r;
+	    }
+	    else if (errno != EINTR)
+	    {
+		/*XXX fixme: report error */
+		close(fd);
+		goto out;
+	    }
+	}
+
+	close(fd);
+    }
+
+    /* fill in the complete length of the table */
+    len = acpi_tables_len - start - sizeof(uint16_t);
+    f = acpi_tables + start;
+    *(uint16_t*)f = cpu_to_le32(len);
+    f += sizeof(uint16_t);
+
+    /* now fill in the header fields */
+    changed = 0;
+
+    /* 0..3, signature, string (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "sig", t))
+    {
+        strncpy(f + 0, buf, 4);
+	++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 0, dfl_id, 4);
+    }
+
+    /* 4..7, length of the table, in bytes, including header (4 bytes) */
+
+    /* 8, ACPI specification minor version #, 1 byte */
+    if (get_param_value(buf, sizeof(buf), "rev", t))
+    {
         val = strtoul(buf, &p, 10);
         if (val > 255 || *p != '\0')
-            goto out;
-    } else {
-        val = 1;
+            goto out;	/*XXX fixme: report error */
+	f[8] = (uint8_t)val;
+	++changed;
+    }
+    else if (!has_header)
+    {
+	f[8] = 1;
     }
-    acpi_hdr.revision = (int8_t)val;
 
-    if (get_param_value(buf, sizeof(buf), "oem_id", t)) {
-        strncpy(acpi_hdr.oem_id, buf, 6);
-    } else {
-        strncpy(acpi_hdr.oem_id, dfl_id, 6);
+    /* 9, checksum of entire table (1 byte) */
+
+    /* 10..15 OEM identification (6 bytes) */
+    if (get_param_value(buf, sizeof(buf), "oem_id", t))
+    {
+        strncpy(f + 10, buf, 6);
+	++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 10, dfl_id, 6);
     }
 
-    if (get_param_value(buf, sizeof(buf), "oem_table_id", t)) {
-        strncpy(acpi_hdr.oem_table_id, buf, 8);
-    } else {
-        strncpy(acpi_hdr.oem_table_id, dfl_id, 8);
+    /* 16..23 OEM table identifiaction, 8 bytes */
+    if (get_param_value(buf, sizeof(buf), "oem_table_id", t))
+    {
+        strncpy(f + 16, buf, 8);
+	++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 16, dfl_id, 8);
     }
 
-    if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {
+    /* 24..27 OEM revision number, 4 bytes */
+    if (get_param_value(buf, sizeof(buf), "oem_rev", t))
+    {
         val = strtol(buf, &p, 10);
         if(*p != '\0')
-            goto out;
-    } else {
-        val = 1;
+            goto out;	/*XXX fixme: report error */
+	*(uint32_t*)(f + 24) = cpu_to_le32(val);
+	++changed;
+    } else if (!has_header)
+    {
+	*(uint32_t*)(f + 24) = cpu_to_le32(1);
     }
-    acpi_hdr.oem_revision = cpu_to_le32(val);
 
-    if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t)) {
-        strncpy(acpi_hdr.asl_compiler_id, buf, 4);
-    } else {
-        strncpy(acpi_hdr.asl_compiler_id, dfl_id, 4);
+    /* 28..31 ASL compiler vendor ID (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "asl_compiler_id", t))
+    {
+        strncpy(f + 28, buf, 4);
+        ++changed;
+    }
+    else if (!has_header)
+    {
+        strncpy(f + 28, dfl_id, 4);
     }
 
-    if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {
+    /* 32..35 ASL compiler revision number (4 bytes) */
+    if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t))
+    {
         val = strtol(buf, &p, 10);
         if(*p != '\0')
-            goto out;
-    } else {
-        val = 1;
+            goto out;	/*XXX fixme: report error */
+	*(uint32_t*)(f + 32) = cpu_to_le32(val);
+	++changed;
     }
-    acpi_hdr.asl_compiler_revision = cpu_to_le32(val);
-
-    if (!get_param_value(buf, sizeof(buf), "data", t)) {
-         buf[0] = '\0';
+    else if (!has_header) {
+	*(uint32_t*)(f + 32) = cpu_to_le32(1);
     }
 
-    length = sizeof(acpi_hdr);
+    /* 4..7 length of the table including header, in bytes (4 bytes) */
+    if (!has_header)
+    {
+	if (!changed)
+	    fprintf(stderr,
+		"warning: acpi table specified with data="
+		" but no table headers are provided, defaults are used\n");
+    }
+    else
+    {
+	/* check if actual length is correct */
+	val = le32_to_cpu(*(uint32_t*)(f + 4));
+	if (val != len)
+	{
+	    fprintf(stderr,
+		"warning: acpi table specified with file= has wrong length,"
+		" header says %lu, actual size %u\n",
+		val, len);
+	    ++changed;
+	}
+    }
 
-    f = buf;
-    while (buf[0]) {
-        struct stat s;
-        char *n = strchr(f, ':');
-        if (n)
-            *n = '\0';
-        if(stat(f, &s) < 0) {
-            fprintf(stderr, "Can't stat file '%s': %s\n", f, strerror(errno));
-            goto out;
-        }
-        length += s.st_size;
-        if (!n)
-            break;
-        *n = ':';
-        f = n + 1;
-    }
-
-    if (!acpi_tables) {
-        acpi_tables_len = sizeof(uint16_t);
-        acpi_tables = qemu_mallocz(acpi_tables_len);
-    }
-    acpi_tables = qemu_realloc(acpi_tables,
-                               acpi_tables_len + sizeof(uint16_t) + length);
-    p = acpi_tables + acpi_tables_len;
-    acpi_tables_len += sizeof(uint16_t) + length;
-
-    *(uint16_t*)p = cpu_to_le32(length);
-    p += sizeof(uint16_t);
-    memcpy(p, &acpi_hdr, sizeof(acpi_hdr));
-    off = sizeof(acpi_hdr);
-
-    f = buf;
-    while (buf[0]) {
-        struct stat s;
-        int fd;
-        char *n = strchr(f, ':');
-        if (n)
-            *n = '\0';
-        fd = open(f, O_RDONLY);
+    /* fix table length */
+    /* we may avoid putting length here if has_header is true */
+    *(uint32_t*)(f + 4) = cpu_to_le32(len);
+
+    /* 9 checksum (1 byte) */
+    /* we may as well leave checksum intact if has_header is true */
+    /* alternatively there may be a way to set cksum to a given value */
+    if (changed || !has_header || 1)
+    {
+	f[9] = 0;
+	f[9] = acpi_checksum((uint8_t*)f, len);
+    }
 
-        if(fd < 0)
-            goto out;
-        if(fstat(fd, &s) < 0) {
-            close(fd);
-            goto out;
-        }
-
-        /* off < length is necessary because file size can be changed
-           under our foot */
-        while(s.st_size && off < length) {
-            int r;
-            r = read(fd, p + off, s.st_size);
-            if (r > 0) {
-                off += r;
-                s.st_size -= r;
-            } else if ((r < 0 && errno != EINTR) || r == 0) {
-                close(fd);
-                goto out;
-            }
-        }
-
-        close(fd);
-        if (!n)
-            break;
-        f = n + 1;
-    }
-    if (off < length) {
-        /* don't pass random value in process to guest */
-        memset(p + off, 0, length - off);
-    }
-
-    acpi_hdr_p = (struct acpi_table_header*)p;
-    acpi_hdr_p->length = cpu_to_le32(length);
-    acpi_hdr_p->checksum = acpi_checksum((uint8_t*)p, length);
     /* increase number of tables */
     (*(uint16_t*)acpi_tables) =
 	    cpu_to_le32(le32_to_cpu(*(uint16_t*)acpi_tables) + 1);
     return 0;
+
 out:
-    if (acpi_tables) {
-        qemu_free(acpi_tables);
-        acpi_tables = NULL;
-    }
+    acpi_tables_len = start;
     return -1;
 }
qemu-options.hx +6 -1
index 18f54d2..e1d26b4 100644
@@ -995,12 +995,17 @@ Enable virtio balloon device (default), optionally with PCI address
 ETEXI
 
 DEF("acpitable", HAS_ARG, QEMU_OPTION_acpitable,
-    "-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,data=file1[:file2]...]\n"
+    "-acpitable [sig=str][,rev=n][,oem_id=str][,oem_table_id=str][,oem_rev=n][,asl_compiler_id=str][,asl_compiler_rev=n][,{data|file}=file1[:file2]...]\n"
     "                ACPI table description\n", QEMU_ARCH_I386)
 STEXI
 @item -acpitable [sig=@var{str}][,rev=@var{n}][,oem_id=@var{str}][,oem_table_id=@var{str}][,oem_rev=@var{n}] [,asl_compiler_id=@var{str}][,asl_compiler_rev=@var{n}][,data=@var{file1}[:@var{file2}]...]
 @findex -acpitable
 Add ACPI table with specified header fields and context from specified files.
+For file=, take whole ACPI table from the specified files, including all
+ACPI headers (possible overridden by other options).
+For data=, only data
+portion of the table is used, all header information is specified in the
+command line.
 ETEXI
 
 DEF("smbios", HAS_ARG, QEMU_OPTION_smbios,
Signature · 1 line
yamahata
#54 lore raw
In reply to Isaku Yamahata
Quoted 7 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Hi,

When I visit the links, the pages say 'You dont have permission'. Could you make these git-repos avaiable again? Thanks in advance.

#55 lore raw
Quoted 6 lines · Hu Tao
Quoted 5 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

Quoted 7 lines
Quoted 2 lines

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Hi,

When I visit the links, the pages say 'You dont have permission'. Could you make these git-repos avaiable again? Thanks in advance.

The link is not for human-reading. Just issue the git command.

Signature · 1 line
yamahata
#56 lore raw
Quoted 10 lines · Isaku Yamahata
Quoted 9 lines · Hu Tao
Quoted 7 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Quoted 6 lines
Quoted 4 lines

Hi,

When I visit the links, the pages say 'You dont have permission'. Could you make these git-repos avaiable again? Thanks in advance.

The link is not for human-reading. Just issue the git command.

Done. Thanks:)

Quoted 2 lines
Signature · 1 line
yamahata
#57 lore raw

I forgot to changet its HEAD. Now it's fixed.
So please change the branch manually or clone the repo again.

Quoted 23 lines · Hu Tao
Quoted 10 lines · Isaku Yamahata
Quoted 9 lines · Hu Tao
Quoted 7 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Quoted 6 lines
Quoted 4 lines

Hi,

When I visit the links, the pages say 'You dont have permission'. Could you make these git-repos avaiable again? Thanks in advance.

The link is not for human-reading. Just issue the git command.

Done. Thanks:)

Quoted 2 lines
Signature · 1 line
yamahata
Signature · 1 line
yamahata
#58 lore raw

Something is still wrong,

I get the following errors now:

:

error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/clone-tmp': Directory not empty

Adnan

_____

From: Isaku Yamahata [mailto:[email protected]]
To: Hu Tao [mailto:[email protected]], Adnan Khaleel [mailto:[email protected]]
Cc: [email protected]
Sent: Wed, 20 Apr 2011 17:46:44 -0500
Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci express support

I forgot to changet its HEAD. Now it's fixed.
So please change the branch manually or clone the repo again.

Quoted 11 lines · Hu Tao
Quoted 10 lines · Isaku Yamahata
Quoted 9 lines · Hu Tao
Quoted 7 lines · Isaku Yamahata

This patch series adds basic q35 chipset support for native pci express support. Some bios related patches are still needed.
For those who want to try it, the following repo is avaiable. (vgabios doesn't need patches, so use the upstream one)

git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/seabios

Quoted 12 lines
Quoted 6 lines
Quoted 4 lines

Hi,

When I visit the links, the pages say 'You dont have permission'. Could you make these git-repos avaiable again? Thanks in advance.

The link is not for human-reading. Just issue the git command.

Done. Thanks:)

Quoted 2 lines
Signature · 1 line
yamahata

--
yamahata

#59 lore raw

Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci?express support

Okay. Can you please try git clone again?

Quoted 62 lines · Adnan Khaleel

Something is still wrong,

I get the following errors now:

:
error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://
people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/ qemu/.git/clone-tmp': Directory not empty

Adnan

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    From: Isaku Yamahata [mailto:[email protected]]
    To: Hu Tao [mailto:[email protected]], Adnan Khaleel
    [mailto:[email protected]]
    Cc: [email protected]
    Sent: Wed, 20 Apr 2011 17:46:44 -0500
    Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci
    express support

    I forgot to changet its HEAD. Now it's fixed.
    So please change the branch manually or clone the repo again.

    On Tue, Apr 19, 2011 at 04:58:32PM +0800, Hu Tao wrote:
    > On Tue, Apr 19, 2011 at 05:51:27PM +0900, Isaku Yamahata wrote:
    > > On Tue, Apr 19, 2011 at 04:28:01PM +0800, Hu Tao wrote:
    > > > On Wed, Mar 16, 2011 at 06:29:11PM +0900, Isaku Yamahata wrote:
    > > > > This patch series adds basic q35 chipset support for native pci
    express
    > > > > support. Some bios related patches are still needed.
    > > > > For those who want to try it, the following repo is avaiable.
    > > > > (vgabios doesn't need patches, so use the upstream one)
    > > > >
    > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
    qemu
    > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
    seabios
    > > >
    > > > Hi,
    > > >
    > > > When I visit the links, the pages say 'You dont have permission'.
    Could
    > > > you make these git-repos avaiable again? Thanks in advance.
    > >
    > > The link is not for human-reading. Just issue the git command.
    >
    > Done. Thanks:)
    >
    > > --
    > > yamahata
    >

    --
    yamahata
Signature · 1 line
yamahata
#60 lore raw

Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci?express support

Hi Yamahata

I'm wondering if there're any PCI-e device emulated by QEmu? And I think the hogplug patches are in this repo, right?

Thanks,
Gui

Quoted 66 lines · Isaku Yamahata

Okay. Can you please try git clone again?

Quoted 62 lines · Adnan Khaleel

Something is still wrong,

I get the following errors now:

:
error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://
people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/ qemu/.git/clone-tmp': Directory not empty

Adnan

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    From: Isaku Yamahata [mailto:[email protected]]
    To: Hu Tao [mailto:[email protected]], Adnan Khaleel
    [mailto:[email protected]]
    Cc: [email protected]
    Sent: Wed, 20 Apr 2011 17:46:44 -0500
    Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci
    express support

    I forgot to changet its HEAD. Now it's fixed.
    So please change the branch manually or clone the repo again.

    On Tue, Apr 19, 2011 at 04:58:32PM +0800, Hu Tao wrote:
    > On Tue, Apr 19, 2011 at 05:51:27PM +0900, Isaku Yamahata wrote:
    > > On Tue, Apr 19, 2011 at 04:28:01PM +0800, Hu Tao wrote:
    > > > On Wed, Mar 16, 2011 at 06:29:11PM +0900, Isaku Yamahata wrote:
    > > > > This patch series adds basic q35 chipset support for native pci
    express
    > > > > support. Some bios related patches are still needed.
    > > > > For those who want to try it, the following repo is avaiable.
    > > > > (vgabios doesn't need patches, so use the upstream one)
    > > > >
    > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
    qemu
    > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
    seabios
    > > >
    > > > Hi,
    > > >
    > > > When I visit the links, the pages say 'You dont have permission'.
    Could
    > > > you make these git-repos avaiable again? Thanks in advance.
    > >
    > > The link is not for human-reading. Just issue the git command.
    >
    > Done. Thanks:)
    >
    > > --
    > > yamahata
    >

    --
    yamahata
#61 lore raw

Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci?express support

In reply to Isaku Yamahata

I still get the same error:

akhaleel@depot5 qemu_0.14_q35 $ git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu
Getting alternates list for http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Getting pack list for http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Getting index for pack c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557
Getting pack c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557
which contains ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
error: cannot unpack 000198da6f46c240e46c562caf57b14268d27597 from /users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack :
:

error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/clone-tmp': Directory not empty

_____

From: Isaku Yamahata [mailto:[email protected]]
To: Adnan Khaleel [mailto:[email protected]]
Cc: Hu Tao [mailto:[email protected]], [email protected]
Sent: Wed, 20 Apr 2011 21:07:46 -0500
Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci?express support

Okay. Can you please try git clone again?

Quoted 53 lines · Adnan Khaleel

Something is still wrong,

I get the following errors now:

:
error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://
people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/ qemu/.git/clone-tmp': Directory not empty

Adnan

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    From: Isaku Yamahata [mailto:[email protected]]
    To: Hu Tao [mailto:[email protected]], Adnan Khaleel
    [mailto:[email protected]]
    Cc: [email protected]
    Sent: Wed, 20 Apr 2011 17:46:44 -0500
    Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci
    express support

    I forgot to changet its HEAD. Now it's fixed.
    So please change the branch manually or clone the repo again.

    On Tue, Apr 19, 2011 at 04:58:32PM +0800, Hu Tao wrote:
    > On Tue, Apr 19, 2011 at 05:51:27PM +0900, Isaku Yamahata wrote:
    > > On Tue, Apr 19, 2011 at 04:28:01PM +0800, Hu Tao wrote:
    > > > On Wed, Mar 16, 2011 at 06:29:11PM +0900, Isaku Yamahata wrote:
    > > > > This patch series adds basic q35 chipset support for native pci
    express
    > > > > support. Some bios related patches are still needed.
    > > > > For those who want to try it, the following repo is avaiable.
    > > > > (vgabios doesn't need patches, so use the upstream one)
    > > > >
    > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
    qemu
    > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
    seabios
    > > >
    > > > Hi,
    > > >
    > > > When I visit the links, the pages say 'You dont have permission'.
    Could
    > > > you make these git-repos avaiable again? Thanks in advance.
    > >
    > > The link is not for human-reading. Just issue the git command.
    >
Quoted 9 lines
    > Done. Thanks:)
    >
    > > --
    > > yamahata
    >

    --
    yamahata

--
yamahata

#62 lore raw

Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native?pci?express support

git clone works for me. Hmmm git installation issue? My git is

$ git --version
git version 1.7.1.1

thanks,

Quoted 110 lines · Adnan Khaleel

I still get the same error:

akhaleel@depot5 qemu_0.14_q35 $ git clone http://people.valinux.co.jp/~yamahata
/qemu/q35/20110316/qemu
Getting alternates list for http://people.valinux.co.jp/~yamahata/qemu/q35/
20110316/qemu/
Getting pack list for http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
qemu/
Getting index for pack c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557 Getting pack c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557
which contains ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
error: cannot unpack 000198da6f46c240e46c562caf57b14268d27597 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
:
:
error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://
people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/ qemu/.git/clone-tmp': Directory not empty

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    From: Isaku Yamahata [mailto:[email protected]]
    To: Adnan Khaleel [mailto:[email protected]]
    Cc: Hu Tao [mailto:[email protected]], [email protected]
    Sent: Wed, 20 Apr 2011 21:07:46 -0500
    Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci?
    express support

    Okay. Can you please try git clone again?

    On Wed, Apr 20, 2011 at 06:41:56PM -0500, Adnan Khaleel wrote:
    > Something is still wrong,
    >
    > I get the following errors now:
    >
    > :
    > error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users
    /
    > akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/
    > pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
    > error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under
    http://
    > people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
    > Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
    > while processing commit 0000000000000000000000000000000000000000.
    > rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/
    qemu_0.14_q35/
    > qemu/.git/clone-tmp': Directory not empty
    >
    > Adnan
    >
    >
    > ?????????????????????????????????????
    > From: Isaku Yamahata [mailto:[email protected]]
    > To: Hu Tao [mailto:[email protected]], Adnan Khaleel
    > [mailto:[email protected]]
    > Cc: [email protected]
    > Sent: Wed, 20 Apr 2011 17:46:44 -0500
    > Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native
    pci
    > express support
    >
    > I forgot to changet its HEAD. Now it's fixed.
    > So please change the branch manually or clone the repo again.
    >
    > On Tue, Apr 19, 2011 at 04:58:32PM +0800, Hu Tao wrote:
    > > On Tue, Apr 19, 2011 at 05:51:27PM +0900, Isaku Yamahata wrote:
    > > > On Tue, Apr 19, 2011 at 04:28:01PM +0800, Hu Tao wrote:
    > > > > On Wed, Mar 16, 2011 at 06:29:11PM +0900, Isaku Yamahata wrote:
    > > > > > This patch series adds basic q35 chipset support for native pci
    > express
    > > > > > support. Some bios related patches are still needed.
    > > > > > For those who want to try it, the following repo is avaiable.
    > > > > > (vgabios doesn't need patches, so use the upstream one)
    > > > > >
    > > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316
    /
    > qemu
    > > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316
    /
    > seabios
    > > > >
    > > > > Hi,
    > > > >
    > > > > When I visit the links, the pages say 'You dont have permission'.
    > Could
    > > > > you make these git-repos avaiable again? Thanks in advance.
    > > >
    > > > The link is not for human-reading. Just issue the git command.
    > >
    > > Done. Thanks:)
    > >
    > > > --
    > > > yamahata
    > >
    >
    > --
    > yamahata
    >

    --
    yamahata
Signature · 1 line
yamahata
#63 lore raw

Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native?pci?express support

Yes, it was a git version conflict. Thanks.

Adnan
_____

From: Isaku Yamahata [mailto:[email protected]]
To: Adnan Khaleel [mailto:[email protected]]
Cc: Hu Tao [mailto:[email protected]], [email protected]
Sent: Thu, 21 Apr 2011 11:38:36 -0500
Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native?pci?express support

git clone works for me. Hmmm git installation issue?
My git is

  $ git --version
  git version 1.7.1.1

thanks,

Quoted 101 lines · Adnan Khaleel

I still get the same error:

akhaleel@depot5 qemu_0.14_q35 $ git clone http://people.valinux.co.jp/~yamahata
/qemu/q35/20110316/qemu
Getting alternates list for http://people.valinux.co.jp/~yamahata/qemu/q35/
20110316/qemu/
Getting pack list for http://people.valinux.co.jp/~yamahata/qemu/q35/20110316/
qemu/
Getting index for pack c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557 Getting pack c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557
which contains ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
error: cannot unpack 000198da6f46c240e46c562caf57b14268d27597 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
:
:
error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users/ akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/ pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under http://
people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb while processing commit 0000000000000000000000000000000000000000.
rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/ qemu/.git/clone-tmp': Directory not empty

    ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
    From: Isaku Yamahata [mailto:[email protected]]
    To: Adnan Khaleel [mailto:[email protected]]
    Cc: Hu Tao [mailto:[email protected]], [email protected]
    Sent: Wed, 20 Apr 2011 21:07:46 -0500
    Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native pci?
    express support

    Okay. Can you please try git clone again?

    On Wed, Apr 20, 2011 at 06:41:56PM -0500, Adnan Khaleel wrote:
    > Something is still wrong,
    >
    > I get the following errors now:
    >
    > :
    > error: cannot unpack fffd440d2ca664a03ee83eabc00107eaf74d7af4 from /users
    /
    > akhaleel/akhaleel/MergeSpace/qemu_0.14_q35/qemu/.git/objects/pack/
    > pack-c0c6d1b7fc8ae79abf99bfb6a402b50e2ec98557.pack
    > error: Unable to find ad620c29c2da573e3a5f13f5b1eb2694fee64cfb under
    http://
    > people.valinux.co.jp/~yamahata/qemu/q35/20110316/qemu/
    > Cannot obtain needed none ad620c29c2da573e3a5f13f5b1eb2694fee64cfb
    > while processing commit 0000000000000000000000000000000000000000.
    > rm: cannot remove directory `/users/akhaleel/akhaleel/MergeSpace/
    qemu_0.14_q35/
    > qemu/.git/clone-tmp': Directory not empty
    >
    > Adnan
    >
    >
    > ?????????????????????????????????????
    > From: Isaku Yamahata [mailto:[email protected]]
    > To: Hu Tao [mailto:[email protected]], Adnan Khaleel
    > [mailto:[email protected]]
    > Cc: [email protected]
    > Sent: Wed, 20 Apr 2011 17:46:44 -0500
    > Subject: Re: [Qemu-devel] [PATCH 00/26] q35 chipset support for native
    pci
    > express support
    >
    > I forgot to changet its HEAD. Now it's fixed.
    > So please change the branch manually or clone the repo again.
    >
    > On Tue, Apr 19, 2011 at 04:58:32PM +0800, Hu Tao wrote:
    > > On Tue, Apr 19, 2011 at 05:51:27PM +0900, Isaku Yamahata wrote:
    > > > On Tue, Apr 19, 2011 at 04:28:01PM +0800, Hu Tao wrote:
    > > > > On Wed, Mar 16, 2011 at 06:29:11PM +0900, Isaku Yamahata wrote:
    > > > > > This patch series adds basic q35 chipset support for native pci
    > express
    > > > > > support. Some bios related patches are still needed.
    > > > > > For those who want to try it, the following repo is avaiable.
    > > > > > (vgabios doesn't need patches, so use the upstream one)
    > > > > >
    > > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316
    /
    > qemu
    > > > > > git clone http://people.valinux.co.jp/~yamahata/qemu/q35/20110316
    /
    > seabios
    > > > >
    > > > > Hi,
    > > > >
    > > > > When I visit the links, the pages say 'You dont have permission'.
    > Could
    > > > > you make these git-repos avaiable again? Thanks in advance.
    > > >
    > > > The link is not for human-reading. Just issue the git command.
    > >
    > > Done. Thanks:)
    > >
    > > > --
    > > > yamahata
Quoted 9 lines
    > >
    >
    > --
    > yamahata
    >

    --
    yamahata

--
yamahata

#64 lore raw

I finally got this work after I realised that the AHCI driver was not being loaded in my disk image and that ACHI was not being enabled in the Seabios .config file. This is really good work Yamahata, thanks.

As far as I can tell, everything works like the stock Qemu 0.14 except networking. The guest OS sees the network device and initialises it but I think the Qemu DHCP server/firewall never gets back, since the network device doesn't even get a 10.0.2.15 ip address during bootup and the guest dhcp client never gets an ip address,

eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   Starting DHCP4 client. . . . . . . .
eth0   DHCP4 continues in background 
eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   DHCP4 client (dhcpcd) is running
eth0   . . . but is still waiting for data
eth0   interface could not be set up until now

So doing an ifconfig later on just shows

eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

lo Link encap:Local loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

I'm going to start a separate thread to see what the possible cause might be and what might be the best way to debug this. Do you have any idea if this q35 chipset going to be committed to Qemu upstream?

Thanks

AK

#65 lore raw
Quoted 38 lines · Adnan Khaleel

I finally got this work after I realised that the AHCI driver was not being loaded in my disk image and that ACHI was not being enabled in the Seabios .config file. This is really good work Yamahata, thanks.

As far as I can tell, everything works like the stock Qemu 0.14 except networking. The guest OS sees the network device and initialises it but I think the Qemu DHCP server/firewall never gets back, since the network device doesn't even get a 10.0.2.15 ip address during bootup and the guest dhcp client never gets an ip address,

eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   Starting DHCP4 client. . . . . . . .
eth0   DHCP4 continues in background 
eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   DHCP4 client (dhcpcd) is running
eth0   . . . but is still waiting for data
eth0   interface could not be set up until now

So doing an ifconfig later on just shows

eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

lo Link encap:Local loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Quoted 1 line

I'm going to start a separate thread to see what the possible cause might be and what might be the best way to debug this. Do you have any idea if this q35 chipset going to be committed to Qemu upstream?

I've recently hacked a bit on q35, rebased it over current master, found and fixed a few bugs to allow booting of WinXP and Win7, and particularly added kvm support to improve testability significantly. You can find my current work at

git://git.kiszka.org/qemu.git q35-test
git://git.kiszka.org/seabios.git q35-test

There are some issues remaining, e.g. usb appeared broken to me. Now I just tested your scenario (e1000+usernet) with a Win7 guest, and I do not get an IP either. There is no traffic on the vlan (I attached a dump device to verify). Looking closer, it seems PCI bar mapping is failing, at least partially, see 'info pci'. I hope it's not yet another ACPI issue. Fixing the polarity bug already forced me to dig way too deep into this horrible domain.

Jan

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#66 lore raw
Quoted 49 lines · Jan Kiszka
Quoted 38 lines · Adnan Khaleel

I finally got this work after I realised that the AHCI driver was not being loaded in my disk image and that ACHI was not being enabled in the Seabios .config file. This is really good work Yamahata, thanks.

As far as I can tell, everything works like the stock Qemu 0.14 except networking. The guest OS sees the network device and initialises it but I think the Qemu DHCP server/firewall never gets back, since the network device doesn't even get a 10.0.2.15 ip address during bootup and the guest dhcp client never gets an ip address,

eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   Starting DHCP4 client. . . . . . . .
eth0   DHCP4 continues in background 
eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   DHCP4 client (dhcpcd) is running
eth0   . . . but is still waiting for data
eth0   interface could not be set up until now

So doing an ifconfig later on just shows

eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

lo Link encap:Local loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Quoted 1 line

I'm going to start a separate thread to see what the possible cause might be and what might be the best way to debug this. Do you have any idea if this q35 chipset going to be committed to Qemu upstream?

I've recently hacked a bit on q35, rebased it over current master, found and fixed a few bugs to allow booting of WinXP and Win7, and particularly added kvm support to improve testability significantly. You can find my current work at

git://git.kiszka.org/qemu.git q35-test
git://git.kiszka.org/seabios.git q35-test

Quoted 7 lines

There are some issues remaining, e.g. usb appeared broken to me. Now I just tested your scenario (e1000+usernet) with a Win7 guest, and I do not get an IP either. There is no traffic on the vlan (I attached a dump device to verify). Looking closer, it seems PCI bar mapping is failing, at least partially, see 'info pci'. I hope it's not yet another ACPI issue. Fixing the polarity bug already forced me to dig way too deep into this horrible domain.

Wow, very great. So is kvm working with q35?

I had a quick look at your patches.
With seabios patch of 94710189f5323034e00b510fe5a0865a7b576a9f, you ignored MCFG area.

(start = Q35_HOST_BRIDGE_PCIEXBAR_ADDR, size = 256MB) is used for MCFG (!= pci region), so it can't be used for PCI region. That's why 256M is added to s.
And Q35_HOST_BRIDGE_PCIEXBAR_ADDR in dev-q35.h also needs to be adjusted.

After pushing out pci id clean up and once they are accepted, I'll publish rebased/cleaned up one.

Signature · 1 line
yamahata
#67 lore raw
Quoted 58 lines · Isaku Yamahata
Quoted 49 lines · Jan Kiszka
Quoted 38 lines · Adnan Khaleel

I finally got this work after I realised that the AHCI driver was not being loaded in my disk image and that ACHI was not being enabled in the Seabios .config file. This is really good work Yamahata, thanks.

As far as I can tell, everything works like the stock Qemu 0.14 except networking. The guest OS sees the network device and initialises it but I think the Qemu DHCP server/firewall never gets back, since the network device doesn't even get a 10.0.2.15 ip address during bootup and the guest dhcp client never gets an ip address,

eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   Starting DHCP4 client. . . . . . . .
eth0   DHCP4 continues in background 
eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   DHCP4 client (dhcpcd) is running
eth0   . . . but is still waiting for data
eth0   interface could not be set up until now

So doing an ifconfig later on just shows

eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

lo Link encap:Local loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Quoted 1 line

I'm going to start a separate thread to see what the possible cause might be and what might be the best way to debug this. Do you have any idea if this q35 chipset going to be committed to Qemu upstream?

I've recently hacked a bit on q35, rebased it over current master, found and fixed a few bugs to allow booting of WinXP and Win7, and particularly added kvm support to improve testability significantly. You can find my current work at

git://git.kiszka.org/qemu.git q35-test
git://git.kiszka.org/seabios.git q35-test

Quoted 7 lines

There are some issues remaining, e.g. usb appeared broken to me. Now I just tested your scenario (e1000+usernet) with a Win7 guest, and I do not get an IP either. There is no traffic on the vlan (I attached a dump device to verify). Looking closer, it seems PCI bar mapping is failing, at least partially, see 'info pci'. I hope it's not yet another ACPI issue. Fixing the polarity bug already forced me to dig way too deep into this horrible domain.

Quoted 1 line

Wow, very great. So is kvm working with q35?

Mostly. The key was to avoid that seabios does smm initialization as that mode is not support by kvm. I also merged the q35 into qemu-kvm to enable in-kernel irqchip support. That finally revealed the polarity issues (only with win7 guests). I also posted a qemu ioapic patch to make it polarity aware as well [1][2].

I also succeeded with passing through a PCIe host device. Nicely, the full set capabilities showed up on the guest side this way. But GPU pass-through did not improve this way (it rather regressed, yet unclear why).

Quoted 9 lines

I had a quick look at your patches.
With seabios patch of 94710189f5323034e00b510fe5a0865a7b576a9f, you ignored MCFG area.

(start = Q35_HOST_BRIDGE_PCIEXBAR_ADDR, size = 256MB) is used for MCFG (!= pci region), so it can't be used for PCI region. That's why 256M is added to s.
And Q35_HOST_BRIDGE_PCIEXBAR_ADDR in dev-q35.h also needs to be adjusted.

Confused. Where was the PCI region located without my hack?

BTW, the PCI bar mapping failures of VGA or e1000 are independent of that seabios commit. You should see them with your tree as well.

Quoted 3 lines

After pushing out pci id clean up and once they are accepted, I'll publish rebased/cleaned up one.

Note that I dropped "simply i440fx initialization". It was a premature cleanup that caused regressions. The good news: I'm working on PAM/SMRAM fixes that will include such a cleanup after removing the need for the init function. The bad news: Those patches will force you to rebase again (to break out the new PAM/SMRAM code).

Jan

[1] http://thread.gmane.org/gmane.comp.emulators.qemu/102459
[2] http://thread.gmane.org/gmane.comp.emulators.qemu/102460

Signature · 2 lines
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux
#68 lore raw
Quoted 4 lines · Jan Kiszka

I also succeeded with passing through a PCIe host device. Nicely, the full set capabilities showed up on the guest side this way. But GPU pass-through did not improve this way (it rather regressed, yet unclear why).

Interesting.

Quoted 10 lines
Quoted 8 lines

I had a quick look at your patches.
With seabios patch of 94710189f5323034e00b510fe5a0865a7b576a9f, you ignored MCFG area.

(start = Q35_HOST_BRIDGE_PCIEXBAR_ADDR, size = 256MB) is used for MCFG (!= pci region), so it can't be used for PCI region. That's why 256M is added to s.
And Q35_HOST_BRIDGE_PCIEXBAR_ADDR in dev-q35.h also needs to be adjusted.

Confused. Where was the PCI region located without my hack?

I mean the following patch on top of your tree.
At the moment, I only compiled it.

src/dev-q35.c +6 -4
index c0aa057..eee50c4 100644
@@ -36,13 +36,15 @@ void mch_mem_addr_init(u16 bdf, void *arg)
 
     /*
      * BUILD_MAX_HIGHMEM == 0xc0000000
-     * [0xc000 0000, 0xf000 0000) for MCFG
-     *  4GB - 1GB, 4GB - 256MB
+     * [0xc000 0000, 0xd000 0000) for MCFG
+     *  3GB ,        3GB + 256MB
+     * [0xd000 0000, 0xf000 0000) for pci memory region
+     *  3GB + 256MB, 4GB - 256MB
      * [0xf000 0000, 0xfec0 0000) for DMI interface(subtractive decode)
      *  4GB - 256MB, 4GB - 20MB
      */
-    s = BUILD_MAX_HIGHMEM;
-    e = s + 128 * 1024 * 1024 - 1 + 512 * 1024 * 1024;
+    s = Q35_HOST_BRIDGE_PCIEXBAR_ADDR + Q35_HOST_BRIDGE_PCIEXBAR_SIZE;
+    e = s + 512 * 1024 * 1024 - 1;
     pci_region_init(addr->pci_bios_mem_region, s, e);
 
     /* pci_bios_mem_addr + <some value: 128M is used here> */
src/dev-q35.h +1 -1
index f5cae62..0d83dba 100644
@@ -8,7 +8,7 @@
 #define  Q35_HOST_BRIDGE_SMRAM          0x9d
 #define Q35_HOST_BRIDGE_PCIEXBAR        0x60
 #define  Q35_HOST_BRIDGE_PCIEXBAR_SIZE  (256 * 1024 * 1024)
-#define  Q35_HOST_BRIDGE_PCIEXBAR_ADDR  0xe0000000
+#define  Q35_HOST_BRIDGE_PCIEXBAR_ADDR   BUILD_MAX_HIGHMEM
 #define  Q35_HOST_BRIDGE_PCIEXBAREN     ((u64)1)
 #define  Q35_HOST_PCIE_PCI_SEGMENT      0
 #define  Q35_HOST_PCIE_START_BUS_NUMBER 0
Quoted 2 lines

BTW, the PCI bar mapping failures of VGA or e1000 are independent of that seabios commit. You should see them with your tree as well.

Hmm, I'll look into it.

Quoted 8 lines
Quoted 2 lines

After pushing out pci id clean up and once they are accepted, I'll publish rebased/cleaned up one.

Note that I dropped "simply i440fx initialization". It was a premature cleanup that caused regressions. The good news: I'm working on PAM/SMRAM fixes that will include such a cleanup after removing the need for the init function. The bad news: Those patches will force you to rebase again (to break out the new PAM/SMRAM code).

Please keep CCed on me.

Signature · 1 line
yamahata
#69 lore raw
In reply to Jan Kiszka
Quoted 49 lines · Jan Kiszka
Quoted 38 lines · Adnan Khaleel

I finally got this work after I realised that the AHCI driver was not being loaded in my disk image and that ACHI was not being enabled in the Seabios .config file. This is really good work Yamahata, thanks.

As far as I can tell, everything works like the stock Qemu 0.14 except networking. The guest OS sees the network device and initialises it but I think the Qemu DHCP server/firewall never gets back, since the network device doesn't even get a 10.0.2.15 ip address during bootup and the guest dhcp client never gets an ip address,

eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   Starting DHCP4 client. . . . . . . .
eth0   DHCP4 continues in background 
eth0   device: Intel Corporation 82540EM Gigabit Ethernet Controller (rev 03)
eth0   DHCP4 client (dhcpcd) is running
eth0   . . . but is still waiting for data
eth0   interface could not be set up until now

So doing an ifconfig later on just shows

eth0 Link encap:Ethernet HWaddr 52:54:00:12:34:56
UP BROADCAST MULTICAST MTU:1500 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

lo Link encap:Local loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

Quoted 1 line

I'm going to start a separate thread to see what the possible cause might be and what might be the best way to debug this. Do you have any idea if this q35 chipset going to be committed to Qemu upstream?

I've recently hacked a bit on q35, rebased it over current master, found and fixed a few bugs to allow booting of WinXP and Win7, and particularly added kvm support to improve testability significantly. You can find my current work at

git://git.kiszka.org/qemu.git q35-test
git://git.kiszka.org/seabios.git q35-test

Quoted 7 lines

There are some issues remaining, e.g. usb appeared broken to me. Now I just tested your scenario (e1000+usernet) with a Win7 guest, and I do not get an IP either. There is no traffic on the vlan (I attached a dump device to verify). Looking closer, it seems PCI bar mapping is failing, at least partially, see 'info pci'. I hope it's not yet another ACPI issue. Fixing the polarity bug already forced me to dig way too deep into this horrible domain.

FWIW, patch below fixes UHCI here. I suspect more bugs in this area as accessing the chip_config registers appears to rely on the host being little endian (direct memcpy).

In contrast, the PCI mapping issue turned out to be a read herring. The unmapped regions were actually ROM BARs which are usually unmapped. And the network issues were related to an outdated DSDT. Somehow rebuilding Seabios did not always properly regenerate them, so my polarity fixes were not inluded. Haven't looked into details, but deleting out/ and src/*.hex resolved that.

I'll have to put this topic aside for now as it looks like we don't depend on it for PCIe pass-through. Still, it's a cool thing, and I would be happy to find it upstream soon!

Jan

------8<-------

From: Jan Kiszka <[email protected]>
Subject: [PATCH] q35: Fix irr initialization for slots 25..31

This was totally off: The CC registers are 16 bit (stored as little endian), their offsets run in reverse order, and D26IR as well as D25IR have 4 bytes offset to their successors.

---
 hw/q35.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
hw/q35.c +7 -3
index a06ea7d..0ab8532 100644
@@ -424,14 +424,18 @@ static void ich9_cc_update_ir(uint8_t irr[PCI_NUM_PINS], uint32_t ir)
 static void ich9_cc_update(ICH9_LPCState *lpc)
 {
     int slot;
-    int reg_offset;
+    int reg;
     int intx;
 
     /* D{25 - 31}IR, but D30IR is read only to 0. */
-    for (slot = 25, reg_offset = 0; slot < 32; slot++, reg_offset++) {
+    for (slot = 31, reg = ICH9_CC_D31IR; slot >= 25; slot--, reg += 2) {
         if (slot != 30) {
             ich9_cc_update_ir(lpc->irr[slot],
-                              lpc->chip_config[ICH9_CC_D31IR + reg_offset]);
+                              lpc->chip_config[reg] |
+                              (uint32_t)lpc->chip_config[reg + 1] << 8);
+        }
+        if (slot <= 27) {
+            reg += 2;
         }
     }
 
Signature · 1 line
1.7.1
#70 lore raw
Quoted 10 lines · Jan Kiszka

FWIW, patch below fixes UHCI here. I suspect more bugs in this area as accessing the chip_config registers appears to rely on the host being little endian (direct memcpy).

In contrast, the PCI mapping issue turned out to be a read herring. The unmapped regions were actually ROM BARs which are usually unmapped. And the network issues were related to an outdated DSDT. Somehow rebuilding Seabios did not always properly regenerate them, so my polarity fixes were not inluded. Haven't looked into details, but deleting out/ and src/*.hex resolved that.

Good catch. I queued it in my repo.

Quoted 50 lines

I'll have to put this topic aside for now as it looks like we don't depend on it for PCIe pass-through. Still, it's a cool thing, and I would be happy to find it upstream soon!

Jan

------8<-------

From: Jan Kiszka <[email protected]>
Subject: [PATCH] q35: Fix irr initialization for slots 25..31

This was totally off: The CC registers are 16 bit (stored as little endian), their offsets run in reverse order, and D26IR as well as D25IR have 4 bytes offset to their successors.

---
 hw/q35.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)
hw/q35.c +7 -3
index a06ea7d..0ab8532 100644
@@ -424,14 +424,18 @@ static void ich9_cc_update_ir(uint8_t irr[PCI_NUM_PINS], uint32_t ir)
 static void ich9_cc_update(ICH9_LPCState *lpc)
 {
     int slot;
-    int reg_offset;
+    int reg;
     int intx;
 
     /* D{25 - 31}IR, but D30IR is read only to 0. */
-    for (slot = 25, reg_offset = 0; slot < 32; slot++, reg_offset++) {
+    for (slot = 31, reg = ICH9_CC_D31IR; slot >= 25; slot--, reg += 2) {
         if (slot != 30) {
             ich9_cc_update_ir(lpc->irr[slot],
-                              lpc->chip_config[ICH9_CC_D31IR + reg_offset]);
+                              lpc->chip_config[reg] |
+                              (uint32_t)lpc->chip_config[reg + 1] << 8);
+        }
+        if (slot <= 27) {
+            reg += 2;
         }
     }
 
Signature · 1 line
1.7.1
Signature · 1 line
yamahata